-->
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.  [ 12 posts ] 
Author Message
 Post subject: @MappedSuperclass
PostPosted: Tue Jan 20, 2009 1:44 pm 
Newbie

Joined: Tue Nov 16, 2004 6:35 pm
Posts: 6
Hi,

Got a @MappedSuperclass question and I will greatly appreciated any help.

Code:
@MappedSuperclass
class A{
       @column(...)
       private Date modifiedDate;
       ...
       ...
}

@MappedSuperclass
class B extends A{
       @column(...)
       private String ....
}


@Entity
class C extends B{
       ....
}

Both class A and B are kind super class (no table behind) that contains commons attributes that C will need. I got repeated column for modifiedDate, should mark it as updatable and insertable to false and it does work if do mark them as false. But I need them to be updatable. I suspect what happened is that the modifiedDate column mapping is brought to class C twice cause the @MappedSuperclass at A and at B. I do not know how to resolve this, could any body point me to the solution? I DO need class A and B separated as well.

Thanks,

Michael


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2009 1:10 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
We've got cases where our mapped superclasses are 5 levels deep and don't have any issue, post some more of your code and maybe something will jump out.

Is modifiedDate in class A AND B? If so, you only need it in 1 of them.

Our case is a bit different as we annotate on the accessors but I can't see annotating on the field being any different behavior.

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2009 2:11 pm 
Newbie

Joined: Tue Nov 16, 2004 6:35 pm
Posts: 6
VampBoy,

Thanks for the answer, here is my exactly code. Would you please check it?

Code:
@MappedSuperclass
public abstract class BaseTrackableBean {

   // Audit Values
   @Column(name="USERID_CREATED", length=15)   
   private String createdUserId;
   @Column(name="USERID_MOD", length=15)
   private String modifiedUserId;
   
   @Temporal(TemporalType.DATE)
    @Column(name="DATE_TIME_CREATED", length=7)
   private Date createdDateTime;
   @Temporal(TemporalType.DATE)
   @Column(name="DATE_TIME_MOD", length=7)
   private Date lastModifiedDateTime;

}

@MappedSuperclass
public class BaseDemographics extends BaseTrackableBean {

   private static final long serialVersionUID = 7182263509267020964L;
   private Long id;
   private Long age;
   private String ethnicityTypeCode;
                ...
}


@Entity
@org.hibernate.annotations.Entity(dynamicInsert=true, dynamicUpdate=true)
@Table(name = "DEMOGRAPHICS")
public class Demographics extends BaseDemographics {
   
   private Long caseId;
   private Contact contact;   
   private String maritalStatus;
   private String childrenFlg = "N";
                ...
}


I can be sure createdDateTime is only the BaseTrackableBean.

and the error is
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: domain.model.Demographics column: createdDateTime (should be mapped with insert="false" update="false")


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2009 10:37 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Is it just the createdDateTime that's causing you an issue? i.e. not the other 3 columns or do they all report the same thing when you mark the createDateTime updatable false, instertable false?

If not then scour your entities and look for a property you mistakenly mapped to DATE_TIME_MOD.

From what you posted it looks fine to me but I suspect those aren't your complete entitities ;)

In your entity classes where are your annotations? Are they at the accessor level or at the field level like the mapped superclass?

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2009 5:14 pm 
Newbie

Joined: Tue Nov 16, 2004 6:35 pm
Posts: 6
Yes, this is all the code :(.

If I comment one, then the next one come up.

Just want to make sure, the @MappedSuperClass at A an B is ok, right?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2009 7:08 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Here's a select sampling of ours...

Code:
@MappedSuperclass
public abstract class HibernateDomainObject  {
    protected String uuid;

    @Transient
    public String getUuid() {
        return this.uuid;
    }
}

@MappedSuperclass
public abstract class UUIDHibernateDomainObject extends HibernateDomainObject {
    @Column(name = "UUID", unique = false, nullable = false, insertable = true, updatable = false)
    public String getUuid() {
        return super.getUuid();
    }
}

@MappedSuperclass
public abstract class AuditableHibernateDomainObject extends UUIDHibernateDomainObject {
    private AuditInfo auditInfo;

    protected AuditableHibernateDomainObject() {
        this.auditInfo = new AuditInfo();
    }

    @Embedded
    public AuditInfo getAuditInfo() {
        return this.auditInfo;
    }

    public void setAuditInfo(AuditInfo auditInfo) {
        AuditInfo oldValue = this.auditInfo;
        this.auditInfo = auditInfo;
        firePropertyChange(AUDIT_INFO_PROPERTY, oldValue, this.auditInfo);
    }
}


We then either come right off the AuditableDomainObject in most of the cases with some cases having another 1 or 2 layers of @MappedSuperClass before getting to the actual entity.

If those are you complete classes, how do you access the private properties?

The other thing I just noticed is that hibernate is reporting the exception as createDateTime rather than DATE_TIME_CREATED which would indicate it's not picking up your name= piece of the annotation.

I've also tried specifying the annotation at the field level in my case and it seems to be working fine.

The only other difference I can see is that your BaseDemographics is a concrete class but I can't see that being an issue either.

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2009 9:33 pm 
Newbie

Joined: Tue Nov 16, 2004 6:35 pm
Posts: 6
There are public get/set for each of the private field of course, which I did not show. I tried the annotation at both field and property. If the field is annotated, hibernate will report that field, ie, createdUserId, need be insert/update false. If property is annotated, hibernate will report column, ie, DATE_TIME_CREATED need be insert/update false. I did not think about the abstract either, I will try to see anyway tomorrow. BTW, I am using hibernate-core.3.2.6.GA, the annotation I tried both 3.2.1 and 3.3.0 and neither work. Which version are you using?

Thanks,

Micahel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2009 11:29 am 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
We're at 3.3 SP1 Core and 3.4 GA Annotations.

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2009 2:53 pm 
Newbie

Joined: Tue Nov 16, 2004 6:35 pm
Posts: 6
Does the one you use work with spring.2.5.6? My understanding is they requires spring 3.0 and that is the reason I did go with it.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2009 3:41 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
We don't use Spring.

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 15, 2009 10:12 pm 
Newbie

Joined: Thu Mar 05, 2009 11:14 pm
Posts: 2
Have you tried making sure serialVersionUIDs exist in all classes of the hierarchy and are all equal?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 16, 2009 6:59 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Where are your annotations in Demographics? Do you annotate the getters there?

If yes, try to annotate the whole hierarchy in a unique way, like allways getters.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 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.