JPA mapping issue with composite key -


i have below mapping

@entity @table(name = "auctions") public class auction{ . .     @onetomany(cascade = cascadetype.all, mappedby = "auction")     private list<auctionparamvalue> auctionparamvaluelist; . . }   @entity @table(name = "auction_param_values") public class auctionparamvalue {      @embeddedid     protected auctionparamvaluepk auctionparamvaluepk;      @joincolumn(name = "auction_param_id", referencedcolumnname = "auction_param_id",updatable=false,insertable=false)     @manytoone          private auctionparam auctionparam;      @joincolumn(name = "auction_id", referencedcolumnname  = "auction_id",updatable=false,insertable=false)     @manytoone @mapsid("auctionid")          private auction auction; }  @embeddable public class auctionparamvaluepk {     @id      @basic(optional = false)     @column(name = "auction_id")     private long auctionid;      @id     @basic(optional = false)     @column(name = "auction_param_id")     private int auctionparamid; }  @entity @table(name = "auction_params")     public class auctionparam {     @onetomany(cascade = cascadetype.all, mappedby = "auctionparam")     private list<auctiontypeparam> auctiontypeparamlist;      @onetomany(cascade = cascadetype.all, mappedby = "auctionparam")     private list<auctionparamvalue> auctionparamvaluelist;  } 

}

when try persist auction getting below error

 internal exception: com.mysql.jdbc.exceptions.mysqlintegrityconstraintviolationexception: column 'auction_param_id' cannot null error code: 1048 call: insert auction_param_values (auction_param_val, create_ts, last_updt_ts, auction_param_id, auction_id) values (?, ?, ?, ?, ?)     bind => [500, 2011-01-25 20:11:01.22, 2011-01-25 20:11:01.22, null, null] query: insertobjectquery(com.eaportal.domain.auctionparamvalue[auctionparamvaluepk=null]) jan 25, 2011 8:11:01 pm org.apache.catalina.core.standardwrappervalve invoke severe: servlet.service() servlet dispatcher threw exception com.mysql.jdbc.exceptions.mysqlintegrityconstraintviolationexception: column 'auction_param_id' cannot null 

for auction - auctionparamvalue relationship need this:

@entity @table(name = "auctions")  public class auction {     @onetomany(cascade = cascadetype.all, mappedby = "auction")     private list<auctionparamvalue> auctionparamvaluelist;     ... }     @entity @table(name = "auction_param_values") public class auctionparamvalue {      @embeddedid      protected auctionparamvaluepk auctionparamvaluepk;       @manytoone @mapsid("auctionid")      private auction auction;       ... } 

regarding auctionparam i'm not sure kind of relationship want express.

you can find complete set of examples of derived identities' mappings (i.e. composite keys foreign keys inside them) in jpa 2.0 specification, section 2.4.1.3.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -