Albert, No there is no reason. I am just prototyping, and had these annotation there. I don't understand what does it have to do with generating the ID column in the DB.
Thank you. On Fri, Jan 31, 2014 at 9:57 AM, Albert Lee <allee8...@gmail.com> wrote: > Is there a reason why you have a @ManyToOne relationship in > > public class GeoAssociationPK implements Serializable { > private Geo fromGeo; > private Geo toGeo; > > @ManyToOne(optional = false) <<<<<< > public Geo getFromGeo() { > return fromGeo; > } > > @ManyToOne(optional = false) <<<<<< > public Geo getToGeo() { > return toGeo; > } > > > On Thu, Jan 30, 2014 at 10:41 PM, Mansour Al Akeel < > mansour.alak...@gmail.com> wrote: > >> Kevin, >> >> Thank you a lot for your time. In fact I fixed the getters and >> setters, and the issue is gone. Now, the issue is with the id field >> being generated in the SQL tables. >> Here's my classes: >> >> >> @Entity >> @Access(AccessType.PROPERTY) >> public class GeoAssoc { >> >> @EmbeddedId >> private GeoAssociationPK id = new GeoAssociationPK(); >> >> private GeoAssocType type; >> >> @ManyToOne(fetch = FetchType.LAZY) >> @JoinColumn(name = "type") >> public GeoAssocType getType() { >> return type; >> } >> >> public void setType(GeoAssocType value) { >> this.type = value; >> } >> >> @Column(name = "from_geo_id") >> public Geo getFromGeo() { >> return this.id.getFromGeo(); >> } >> >> public void setFromGeo(Geo fromGeo) { >> this.id.setFromGeo(fromGeo); >> } >> >> @Column(name = "to_geo_id") >> public Geo getToGeo() { >> return this.id.getToGeo(); >> } >> >> public void setToGeo(Geo toGeo) { >> this.id.setToGeo(toGeo); >> } >> >> @Override >> public boolean equals(Object obj) { >> throw new UnsupportedOperationException("Not implemented"); >> } >> >> @Override >> public int hashCode() { >> throw new UnsupportedOperationException("Not implemented"); >> } >> >> } >> >> >> >> >> @Embeddable >> public class GeoAssociationPK implements Serializable { >> >> private Geo fromGeo; >> >> private Geo toGeo; >> >> >> @ManyToOne(optional = false) >> public Geo getFromGeo() { >> return fromGeo; >> } >> >> public void setFromGeo(Geo fromGeo) { >> this.fromGeo = fromGeo; >> } >> >> @ManyToOne(optional = false) >> public Geo getToGeo() { >> return toGeo; >> } >> >> public void setToGeo(Geo toGeo) { >> this.toGeo = toGeo; >> } >> >> @Override >> public boolean equals(Object obj) { >> throw new UnsupportedOperationException("Not implemented"); >> } >> >> @Override >> public int hashCode() { >> throw new UnsupportedOperationException("Not implemented"); >> } >> } >> >> >> The generated table has 4 fields (type, from_geo_id , to_geo_id , and >> id). The last columns "id" is not needed, and don't know how to tell >> the persistence classes to ignore it and not to generate it in the DB. >> This is why I have PROPERTY access type, but still it's generated. Any >> advice about how to do this ?? >> >> >> Thank you. >> >> On Thu, Jan 30, 2014 at 9:53 AM, Kevin Sutter <kwsut...@gmail.com> wrote: >> > Hi Mansour, >> > I agree that the message is messed up a bit... This particular message >> is >> > used in a few different locations in the code. If you have additional >> > context about when this is received (call stack, persistent operation, >> > etc), it would help with identifying the specific usage and get that >> > cleaned up. >> > >> > Looking at your example, a couple of things jump out... >> > >> > 1) In your PK class, your getter/setter methods don't match the strId >> > attribute (get/setMessage?). These names need to follow standard java >> bean >> > conventions and need to match up. >> > >> > 2) In your GeoAssociation class... It looks like you want the ability >> to >> > setGeo and setStrId, but I don't see those methods defined. You have >> them >> > defined (sort of, per my first comment) in your PK class. But, you don't >> > have them defined in your GeoAssoc class. >> > >> > That's all I've got at this point. >> > Kevin >> > >> > >> > On Wed, Jan 29, 2014 at 11:48 PM, Mansour Al Akeel < >> > mansour.alak...@gmail.com> wrote: >> > >> >> Hello all, >> >> >> >> I need to create a primary key in my tables, and set constrains on >> >> them. So I have few tables: >> >> >> >> 1- Geo >> >> 2- GeoAssociation >> >> >> >> For the GeoAssociation, I need a primary key GeoAssociationPK. The PK >> >> has a field, that "HAS" to be a geo_id. So here's the definition I >> >> have for GeoAssociation: >> >> >> >> >> >> >> >> @Embeddable >> >> public class GeoAssociationPK implements Serializable { >> >> >> >> private String strId; >> >> >> >> private Geo geo; >> >> >> >> @Column(name = "str_id") >> >> public String getMessage() { >> >> return strId; >> >> } >> >> >> >> public void setMessage(String message) { >> >> this.strId = message; >> >> } >> >> >> >> @ManyToOne(optional = false) >> >> @Column(name = "geo_id") >> >> public Geo getGeo() { >> >> return geo; >> >> } >> >> >> >> public void setGeo(Geo geoFrom) { >> >> this.geo = geoFrom; >> >> } >> >> >> >> @Override >> >> public boolean equals(Object obj) { >> >> throw new UnsupportedOperationException("Not implemented"); >> >> } >> >> >> >> @Override >> >> public int hashCode() { >> >> throw new UnsupportedOperationException("Not implemented"); >> >> } >> >> >> >> } >> >> >> >> >> >> >> >> This is how I define the GeoAssociation class: >> >> >> >> @Entity >> >> @Access(AccessType.PROPERTY) >> >> >> >> public class GeoAssoc { >> >> >> >> @EmbeddedId >> >> private GeoAssociationPK id = new GeoAssociationPK(); >> >> >> >> private GeoAssocType type; >> >> >> >> @ManyToOne(fetch = FetchType.LAZY) >> >> @JoinColumn(name = "type") >> >> public GeoAssocType getType() { >> >> return type; >> >> } >> >> >> >> public void setType(GeoAssocType value) { >> >> this.type = value; >> >> } >> >> >> >> public Geo getGeoFrom() { >> >> return this.id.getGeo(); >> >> } >> >> >> >> @Override >> >> public boolean equals(Object obj) { >> >> throw new UnsupportedOperationException("Not implemented"); >> >> } >> >> >> >> @Override >> >> public int hashCode() { >> >> throw new UnsupportedOperationException("Not implemented"); >> >> } >> >> >> >> } >> >> >> >> >> >> The error I am getting when building with maven enhancer is: >> >> >> >> The id class specified by type "class entities.geo.GeoAssoc" does not >> >> match the primary key fields of the class. Make sure your identity >> >> class has the same primary keys as your persistent type, including pk >> >> field types. Mismatched property: "geo" -> [Help 1] >> >> >> >> I don't understand the error message or how to solve it. What I need >> >> is to be able to create and persist entity without having to >> >> explicitly create the PK. >> >> >> >> For example : >> >> GeoAssociation gs = new GeoAssociation(); >> >> gs.setGeo(myGeo); >> >> gs.setStrId(someString); >> >> >> >> >> >> My question is how to achieve this, and resolve this error message ? >> >> >> >> >> >> Thank you in advance. >> >> >> > > > > -- > Albert Lee.