-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: 1:1 Relation shared primary keys
PostPosted: Fri May 07, 2010 1:06 pm 
Newbie

Joined: Thu Oct 29, 2009 2:59 am
Posts: 10
Hello,

ich tried to establish a 1:1 relation between 2 tables but it doesn't work.
Above is the code, I get the following exception:

Quote:
ids for this class must be manually assigned before calling save(): at.eventtiming.domain.Contact; nested exception is
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save():
at.eventtiming.domain.Contact


Code:
public final class DaoMain {

    public static void main(String[] args) {
   
    final ApplicationContext ctx = new FileSystemXmlApplicationContext("src/service.xml");
    final HibernateParticipantDao dao = (HibernateParticipantDao) ctx.getBean("participantDao");
    final Participant participant = new Participant();
    participant.setFirstname("Hans");
    participant.setSurname("Maier");
    //participant.setChipnumber("DF-12345");
    final Contact contact = new Contact();
    contact.setEmail("hans.mair@web.de");
    contact.setTelnumber("0664/534508697");
    participant.setContact(contact);
    dao.saveParticipant(participant);

    final List<Participant> participantList = dao.getAllParticipants();
    System.out.println("ParticipantList: " + participantList);
  }
}


Code:
@Entity
@SuppressWarnings("serial")
@Table(name="TParticipant")
public class Participant implements Serializable {

  private Integer pk_part;
  private String firstname;
  private String surname;
  private String chipnumber;
  private Contact contact;
 
  public Participant() {}

  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  public Integer getPk_part() {
    return pk_part;
    }

  public void setPk_part(final Integer pk_part) {
    this.pk_part = pk_part;
    }

  @OneToOne(cascade = CascadeType.ALL)
  @PrimaryKeyJoinColumn
  public Contact getContact() {
    return contact;
    }

  public void setContact(final Contact contact) {
    this.contact = contact;
    }   
...


Code:
@Entity
@SuppressWarnings("serial")
@Table(name="TContact")
public class Contact implements Serializable {

    @Id
    private Integer pk_contact;
    private String email;
    private String telnumber;
    private String fax;

    public Contact() {}

    public Integer getPk_contact() {
        return pk_contact;
        }

    public void setPk_contact(final Integer pk_contact) {
        this.pk_contact = pk_contact;
        }


Top
 Profile  
 
 Post subject: Re: 1:1 Relation shared primary keys
PostPosted: Sat May 08, 2010 7:01 am 
Newbie

Joined: Thu Oct 29, 2009 2:59 am
Posts: 10
Has anyone an idea how to do,
Thanks for replies,
All the best,


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.