-
1. Re: Inheritence
adamw Nov 12, 2008 4:25 AM (in response to amin1977)Hello,
which inhertinace type do you use? Currently, only single-table inheritance will work. For support on the others, watch the progress on http://opensource.atlassian.com/projects/hibernate/browse/HHH-3564.
--
Adam -
2. Re: Inheritence
amin1977 Nov 12, 2008 5:40 AM (in response to amin1977)I am using single-table inheritence at the moment
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
Still can't see the address that I've added. -
3. Re: Inheritence
adamw Nov 12, 2008 5:48 AM (in response to amin1977)Can you please post your entities?
--
Adam -
4. Re: Inheritence
amin1977 Nov 12, 2008 6:15 AM (in response to amin1977)Contact.java
@Entity @org.hibernate.annotations.Entity( selectBeforeUpdate = true, dynamicInsert = true, dynamicUpdate = true) @Table(name="T_CONTACT") @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorValue("Contact") @DiscriminatorColumn(name="contactType",discriminatorType=javax.persistence.DiscriminatorType.STRING) @Versioned @Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL) public class Contact implements Serializable { @SuppressWarnings("unused") private static Logger logger = Logger.getLogger(Contact.class); private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="C_CONTACT_ID") @Type(type="java.lang.Long") @DocumentId private Long id; @Column(name="C_EMAIL") @Field(index=Index.TOKENIZED, store=Store.YES) private String email; @Column(name="C_CREATEDON") @Type(type="java.util.Date") private Date createdOn; @Column(name="C_LASTUPDATEDON") @Type(type="java.util.Date") private Date lastUpdatedOn; @OneToMany(mappedBy="contact",targetEntity=com.amin.gigaspaces.common.domain.Address.class, cascade = { CascadeType.ALL}, fetch=FetchType.EAGER) @IndexedEmbedded @JoinColumn(name="C_CONTACT_ID") @Type(type="java.util.Set") @Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL) private Set<Address> addresses; @OneToMany(mappedBy="contact", targetEntity=com.amin.gigaspaces.common.domain.Phone.class,cascade = { CascadeType.ALL}, fetch=FetchType.EAGER) @IndexedEmbedded @JoinColumn(name="C_CONTACT_ID") @Type(type="java.util.Set") @Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL) private Set<Phone> phoneNumbers; @OneToMany(mappedBy="contact", targetEntity=com.amin.gigaspaces.common.domain.Note.class,cascade = { CascadeType.ALL}, fetch=FetchType.EAGER) @IndexedEmbedded @JoinColumn(name="C_CONTACT_ID") @Type(type="java.util.Set") @Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL) private Set<Note> contactNotes; @Column(name="C_NOTES") @Field(index=Index.TOKENIZED, store=Store.YES) private String notes; @Column(name="C_TRASHED") private boolean trashed; ...getters and setters
PersonalContact.java@Entity @DiscriminatorValue("PersonalContact") @SuppressWarnings("serial") @Versioned @Indexed public class PersonalContact extends Contact { @Column(name="P_FIRSTNAME") @Field(index=Index.TOKENIZED, store=Store.YES) private String firstname; @Column(name="P_SURNAME") @Field(index=Index.TOKENIZED, store=Store.YES) private String surname; @Column(name="P_DATEOFBIRTH") @Type(type="java.util.Date") private Date dateOfBirth; @Column(name="P_NOTIFYBIRTHDAY") @Type(type="boolean") private boolean notifyBirthDay; @Column(name="P_MYFACESURL") @Field(index=Index.TOKENIZED, store=Store.YES) private String myFacesUrl; @Column(name="P_REMINDERCOUNT") private int reminderCount; @Column(name="P_REMINDERRESET") @Type(type="boolean") private boolean reset; ...getters and setters
Address.java@Entity @org.hibernate.annotations.Entity( selectBeforeUpdate = true, dynamicInsert = true, dynamicUpdate = true) @Indexed @Table(name="T_ADDRESS") @Versioned @Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL) public class Address implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="A_ADDRESS_ID") @Type(type="java.lang.Long") @DocumentId private Long id; @Column(name="A_ADDRESS1") @Field(index=Index.TOKENIZED, store=Store.YES) private String address1; @Column(name="A_ADDRESS2") @Field(index=Index.TOKENIZED, store=Store.YES) private String address2; @Column(name="A_TOWN") @Field(index=Index.TOKENIZED, store=Store.YES) private String town; @Column(name="A_COUNTY") @Field(index=Index.TOKENIZED, store=Store.YES) private String county; @Column(name="A_COUNTRY") @Field(index=Index.TOKENIZED, store=Store.YES) private String country; @Column(name="A_POSTCODE") @Field(index=Index.TOKENIZED, store=Store.YES) private String postcode; @Column(name="A_ACTIVE") @Type(type="boolean") private boolean active; @Column(name="A_CREATEDON") @Type(type="java.util.Date") private Date createdOn; @Column(name="A_LASTUPDATEDON") @Type(type="java.util.Date") private Date lastUpdatedOn; @ContainedIn @ManyToOne @JoinColumn(name="C_CONTACT_ID", nullable=false, insertable=true, updatable=true) private Contact contact; ...getters and setters
Hope that helps. -
5. Re: Inheritence
amin1977 Nov 13, 2008 4:24 AM (in response to amin1977)Hi
I was looking at the other posts and noticed someone used@VersionsJoinTable
Do I need to use this for my OneToMany collection? -
6. Re: Inheritence
adamw Nov 13, 2008 4:43 AM (in response to amin1977)Hello,
no, @VersionsJoinTable is optional and only useful for unidirectional @OneToMany relations.
Could you maybe create a test case and post a JIRA bug?
--
Thanks,
Adam -
7. Re: Inheritence
amin1977 Nov 13, 2008 11:31 AM (in response to amin1977)Sure. I'm just wondering if it;s something I am doing wrong rather than it being a bug.
Here is what I am doing:
1) Create a personal contact with no address (email = test@test.com)
2) Update personal contact email address (email = test2@test.com)
At this point I get back one entity in the list.
3) I add address to personal contact
At this stage I have an entry in the revisions table for personal contact with contactType being Contact rather than personal contact
4) Add another address to personal contact
When I inspect the entities in the collection they don't have any address attached to them. When I added the 2nd address should I not see the first address in the personal contact set when I inspect the personal contact history?
As I mentioned I am happy to raise a JIRA but I'm not sure if this is a bug... -
8. Re: Inheritence
adamw Nov 13, 2008 2:16 PM (in response to amin1977)Hello,
it sounds like it may be a bug :) The adressess should of course be in the history of the contact. If they appear in the "real" entities, they should also appear in the history :).
--
Adam -
9. Re: Inheritence
amin1977 Nov 13, 2008 3:55 PM (in response to amin1977)Hi
I will raise a JIRA issue, I could not find Envers project when creating a JIRA using the below url:
http://opensource.atlassian.com/projects/hibernate/secure/CreateIssue!default.jspa
Can I put under another project?
Thanks -
10. Re: Inheritence
amin1977 Nov 13, 2008 4:06 PM (in response to amin1977)Got it...sorry I know where to put it. Just had another daughter so not getting enough sleep!
-
11. Re: Inheritence
adamw Nov 13, 2008 4:33 PM (in response to amin1977)Yeah, just use the envers component.
Congratulations! :)
Adam -
-
13. Re: Inheritence
amin1977 Nov 13, 2008 4:54 PM (in response to amin1977)I'm using Spring and Hibernate together, is it ok to add the Spring testcase to the JIRA?
-
14. Re: Inheritence
adamw Nov 14, 2008 9:43 AM (in response to amin1977)Hello,
I've identified the bug so now it's just a matter of solving it ;)
--
Adam