[jboss-user] [EJB3] - @PrimaryKeyJoinColumn - exception

Hubert Lyczek do-not-reply at jboss.com
Sun Jan 16 07:52:22 EST 2011

Hubert Lyczek [http://community.jboss.org/people/lysy78] created the discussion

"@PrimaryKeyJoinColumn - exception"

To view the discussion, visit: http://community.jboss.org/message/581026#581026


I've dicided to try one-to-one relation using @PrimaryKeyJoinColumn. But i cannot force it to work.

- AS: jboss-6.0.0.Final
- java version "1.6.0_23"

Problem description:
I have two entities: Customer, Address. Relation between Customer and address is bidirectional one-to-one. The relation  uses primary keys.
You can see created entity beans below:

public class Customer implements Serializable{
     @Column(name="CUSTOMER_ID", nullable=false)
     private Integer customerId;
     @OneToOne(fetch=FetchType.EAGER, cascade=CascadeType.ALL, optional=true)
      private Address address;  

public class 
Address implements Serializable{      
     @Column(name="ADDRESS_ID", nullable=false)
     @GeneratedValue(generator="foreignGenerator")     @GenericGenerator(
          name="foreignGenerator", strategy="foreign", 
          parameters={@Parameter(name="property", value="customer"
     )})     private Integer addressId;
     @OneToOne(mappedBy="address", fetch=FetchType.LAZY, optional=false) 
      private Customer customer; 



As you see i'm using @GeneratedValue and @GenericGenerator to be sure that address_id will be the same as customer_id.
Unfortunately that doesn't work.

I tried to run code (from remote client):

Customer customer = new Customer();
...          //set customer fields
 Address address = new Address();
 ...          //set addres fields

databaseManager.createCustomer(customer);     //persist

This is implementation of method createCustomer.

public void 

Unfortunately when i try to persist customer with address i get this exception:

Exception in thread "main" javax.ejb.EJBTransactionRolledbackException: 
org.hibernate.id.IdentifierGenerationException: null id generated for:class hl.test.relations.entity.Address
     at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.handleInCallerTx(

I thought that i would get the same id for Address as for Customer. But i got exeption and i don't know why.
Could you guys help me find out where is the reason of the exception and how to fix my code?

Thank you in advance


Reply to this message by going to Community

Start a new discussion in EJB3 at Community

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110116/8c5349fb/attachment-0001.html 

More information about the jboss-user mailing list