org.hibernate.exception.DataException: could not insert: [models.User]

5,137 views
Skip to first unread message

Andru

unread,
Nov 28, 2010, 9:27:50 PM11/28/10
to play-framework
Hello all,
can someone help me please, i'm really having a hard time with the jpa
model save() function:

Here is my code:

@Entity
@Table(name="tb_users")
public class User extends Model{

@Required
@Match(value="^\\w*$", message="Not a valid username")
private String username;

@Required
private String password;

private String ip;

@Email
@Required
private String email;

@Email
@Required
private String pemail;

public User(String username,String password, String ip,String email,
String pemail){
this.username = username;
this.password = Codec.hexMD5(password).toString();
this.ip = ip;
this.email = email;
this.pemail = pemail;
save();
}
getters()+setters()
}

And in the "tb_users" table i have this:

id as BIGINT not null auto-increment
username as varchar not null
password as varchar notnull
ip as varchar not null
email as varchar notnull
pemail as varchar not null.

In application.conf file i have the following 4 lines uncommented:

db.url=jdbc:mysql://127.0.0.1:3306/mydb
db.driver=com.mysql.jdbc.Driver
db.user=root
db.pass=

my db has no password.
the line "jpa.dialect=org.hibernate.dialect.PostgreSQLDialect" is
still commented.

everytime i try to instantiate a new User i get the
"PersistenceException occured:org.hibernate.exception.DataException:
could not insert: [models.User]" message, pointing at the save()
function in the User constructor.

Please help.
Regards.

Julien Tournay

unread,
Nov 29, 2010, 4:30:30 AM11/29/10
to play-fr...@googlegroups.com
Hi,

I think you should not call "save()" in a constructor and I just can't imagine why you want to call that here.
That's probably the cause of you're error. If not, can you post the full stacktrace ?

jto.



--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.




--
Real Programmers don't need comments-- the code is obvious.

grandfatha

unread,
Nov 29, 2010, 7:15:07 AM11/29/10
to play-framework
You need to give more details (the stacktrace), otherwise I cannot
help right now.

Guillaume Bort

unread,
Nov 29, 2010, 8:31:44 AM11/29/10
to play-fr...@googlegroups.com
Yes please send us the related SQL error.

On Mon, Nov 29, 2010 at 1:15 PM, grandfatha <dki...@googlemail.com> wrote:
> You need to give more details (the stacktrace), otherwise I cannot
> help right now.
>

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>

--
Guillaume Bort, http://guillaume.bort.fr

For anything work-related, use g...@zenexity.fr; for everything else,
write guillau...@gmail.com

Andru

unread,
Nov 29, 2010, 8:37:51 AM11/29/10
to play-framework
Hello and thank you very much,
i've just solved my problem just after you mentionned the stacktrace
thing,lol.

After reading the stackTrace() in the console, i found out that the ip
data from the user was too big for the ip column in the database.
So i just increased the ip's varchar size and it worked!

I'm a beginner, as you guys have guessed.

Mille merci o:
Regards.
Reply all
Reply to author
Forward
0 new messages