-->
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: Problem persisting a class with hibernate
PostPosted: Thu Mar 31, 2011 11:24 am 
Newbie

Joined: Thu Mar 31, 2011 11:10 am
Posts: 2
Hello,

I have a class Person that i want to persist via hibernate.
The class has several attributes like name, firstname, and so on.

Code:
@Entity
@Table(name = "PERSON")
public class Person {
 
  /**
   * serial id
   */
  private static final long serialVersionUID = 8924573169941152854L;
 
  private final static transient String SIMPLE_NAME = Person.class.getSimpleName();
 
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private long uuid;

@OneToOne(optional = false, cascade = CascadeType.ALL)
  @JoinTable(name = "PERSON_TO_NAME")
  private StringModelItem name = new StringModelItem();

  @OneToOne(optional = false, cascade = CascadeType.ALL)
  @JoinTable(name = "PERSON_TO_FIRST_NAME")
  private StringModelItem firstName = new StringModelItem();
   
  @Column(name = "GENDER", nullable = false, unique = false)
  private GenderType gender;
 
  @Column(name = "FAMILY_STATUS", nullable = false, unique = false)
  private FamilyStatusTyp familyStatus;
 
  @Column(name = "DATE_OF_BIRTH", nullable = false, unique = false)
  private Date dateOfBirth;
 
  ....
};


I am using for name and firstname a class StringModelItem that holdes besides the name value as String,
several transient meta data.

Code:
@Entity
@Table(name = "STRING_MODEL_ITEMS")
public class StringModelItem {
 
  /**
   * serialVersionUID
   */
  private static final long serialVersionUID = -1;
 
  @Column(name = "VALUE", nullable = false, length = 20, unique = false)
  private String value;
...
};



I need this structure for several reasons. But i do not like the jointable assignment for that attributes.
Best would be to configure hibernate in a way, that the attribute name will be stored in the PERSON-table
and the jointable will not be needed. It is not important using Annotations or a config file.
I just need the StringModelItem class as attribute type and want to store a value from that class in the Person-table.
Loading from that table should also work.

Is this possible?? Anyone can help??


Top
 Profile  
 
 Post subject: Re: Problem persisting a class with hibernate
PostPosted: Thu Mar 31, 2011 12:07 pm 
Newbie

Joined: Thu Mar 31, 2011 11:10 am
Posts: 2
Ok, i found the solution myself.

For configuration with xml i use component tag.

@Embeded and @AttributeOverrides do the same with annotations.

thx.


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.