Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPA error (A JPA error occurred (Unable to build EntityManagerFactory))
JPA error [message #892934] Mon, 02 July 2012 02:05 Go to next message
myesther ghee is currently offline myesther gheeFriend
Messages: 2
Registered: July 2012
Junior Member
Good day everyone!

I hope i'm in a right site and forum. i am new to eclipse and play framework and i'm stock to this error message:

JPA error

A JPA error occurred (Unable to build EntityManagerFactory): Foreign key (FKDFF242144FD6CDC4:Comments [])) must have same number of columns as the referenced primary key (Post [author_uid])


i have three tables:

1. @Entity
public class Users extends GenericModel {

@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid2")
@Expose
public String uid;
public String email;
public String password;
public String fullname;
public boolean isAdmin;

public Users(String email, String password, String fullname) {
this.email = email;
this.password = password;
this.fullname = fullname;
}

public static Users connect(String email, String password) {
return find("byEmailAndPassword", email, password).first();
}


}

2. @Entity
public class Post extends GenericModel{


@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid2")
@Expose

@ManyToOne
public Users author;

public String id;
public String title;
@Lob
public String contain;

@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
public DateTime dateposted;

@OneToMany(mappedBy="posts", cascade=CascadeType.ALL)
public List<Comments> comments;

public Post(Users author, String title, String contain) {
this.comments = new ArrayList<Comments>();
this.author = author;
this.title = title;
this.contain = contain;
this.dateposted = new DateTime();
}

public Post addComment(String author, String contain) {
Comments newComment = new Comments(this, author, contain).save();
this.comments.add(newComment);
return this;
}
}

3. @Entity
public class Comments extends GenericModel{
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid2")
@Expose

public String cid;
public String author;

@Lob
public String contain;
@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
public DateTime dateposted;
@ManyToOne
public Post posts;

public Comments(Post posts, String author, String contain) {
this.posts = posts;
this.author = author;
this.contain = contain;
this.dateposted = new DateTime();
}
}

the error did not appear for the first two tables, but after defining the third table, the error keep displaying in my browser...

anyone can enlighten me on this...

thanks in advance...

myes,
Re: JPA error [message #893292 is a reply to message #892934] Tue, 03 July 2012 13:20 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello,

It appears you are using Hibernate as your JPA provider - this forum is for EclipseLink, an alternate JPA provider, so you may want to post your problem on a more appropriate forum or try EclipseLink.

That said, my guess would be that the problem is due to the Comments->Post ManyToOne mapping specifying the defaults. For some reason, it thinks the Post entity has two or more id fields as a composite ID. This could be due to putting the @ID and @GeneratedValue on the ManyToOne 'author' relationship, though this could be a hibernate issue. I don't think a sequence should be used for a relationship field so a validation exception should be thrown, or it just ignored since the field should be set from the User object instead of a generator.

More likely, you meant to put the @ID and generator on the id string defined below the relationship?

Best Regards,
Chris
Re: JPA error [message #894664 is a reply to message #893292] Tue, 10 July 2012 03:39 Go to previous message
myesther ghee is currently offline myesther gheeFriend
Messages: 2
Registered: July 2012
Junior Member
Chris,

thank you for the reply... yes, i figured it out why i got the error and your right it just i was not able to comeback here.

thank you also for acknowledging my post even though it is not fitted here.

God bless....
Previous Topic:Persistence.xml question
Next Topic:Eclipselink + Websphere 7
Goto Forum:
  


Current Time: Thu Apr 18 23:09:59 GMT 2024

Powered by FUDForum. Page generated in 0.01765 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top