-->
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.  [ 15 posts ] 
Author Message
 Post subject: Multiple Entities mapped to the same table causes error
PostPosted: Fri Apr 07, 2006 9:21 pm 
Beginner
Beginner

Joined: Tue Aug 03, 2004 1:13 pm
Posts: 23
Im using the Hibernate Entity Manager/Annotations with a mix of @Entity mapped and hbm.xml mapped entities.

I have a heavyweight entity and a lightweight entity mapped to the the same table. If i map them using hbm files there is no error.

If i update one of them to @Entity mapped (leaving the other as an hbm) it also works.

If I have both mapped via @Entity it failes :

0:06:07,195 INFO [STDOUT] org.hibernate.DuplicateMappingException: Duplicate table mapping Store
at org.hibernate.cfg.Mappings.addDenormalizedTable(Mappings.java:192)
at org.hibernate.cfg.annotations.TableBinder.fillTable(TableBinder.java:107)
at org.hibernate.cfg.annotations.EntityBinder.bindTable(EntityBinder.java:291)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:466)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:276)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:210)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:997)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:722)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:161)
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:567)
at org.hibernate.ejb.Ejb3Configuration.createContainerEntityManagerFactory(Ejb3Configuration.java:245)



Is there something special I have to do for this to work in straight EJB3? Or is ther some alternate way to do it?


Last edited by cmrudd on Thu Apr 13, 2006 10:23 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 13, 2006 9:37 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Use inharitance strategy - SINGLE TABLE.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 13, 2006 10:23 am 
Beginner
Beginner

Joined: Tue Aug 03, 2004 1:13 pm
Posts: 23
I cant use inheritence, as they dont have an ancestor/descendant relationship. One is just a subview of the other. Also I cannot modify the code/mapping of the "true" entity. I only have control over the view entity.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 13, 2006 10:29 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Maybe setting class attribute polymorphism="explicit" can help.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 13, 2006 10:34 am 
Beginner
Beginner

Joined: Tue Aug 03, 2004 1:13 pm
Posts: 23
Ive tried using
@org.hibernate.annotations.Entity(mutable=false, polymorphism=PolymorphismType.EXPLICIT)

To make it a read only explicit entity, but it still fails because there is already a table defined in the metadata (because of the previous entity)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 13, 2006 12:14 pm 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Hmmm ...
Which db are you using?
Since when I used mssql I had a view on this table and a sub class mapped with explicit polymorphism and it worked.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 16, 2006 1:12 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Can you show me how you map them using annotaitons?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 26, 2006 3:16 pm 
Beginner
Beginner

Joined: Tue Aug 03, 2004 1:13 pm
Posts: 23
@Entity mapped class (no code relationhip with Store class, just a simple view of it (not all properties mapped)

Code:
@SuppressWarnings("serial")
@Entity
@org.hibernate.annotations.Entity(mutable=false)
@Table(name="Store")
public class PickerStore implements Serializable
{
    @Id @Column(name="I_STORE_ID") @GeneratedValue(generator="system-uid") @GenericGenerator(name="system-uid", strategy="uuid.hex")
    private String id;

    @Column(name="STORE_ID")
    private int userKey;

    @Column(name="SHORT_DESCRIPTION")
    private String shortDescription;

    @Column(name="LONG_DESCRIPTION")
    private String longDescription;

    public String getId() { return id; }
    public int getUserKey() { return userKey; }
    public String getShortDescription() { return shortDescription; }
    public String getLongDescription() { return longDescription; }
}


HBM mapped Store class.
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-lazy="false"
>
    <class
        name="Store"
        table="STORE"
        dynamic-update="false"
        dynamic-insert="false"
        select-before-update="false"
        optimistic-lock="version"
    >

        <id
            name="id"
            column="I_Store_Id"
            type="java.lang.String"
            access="field"
        >
            <generator class="uuid.hex">
            </generator>
        </id>

        <version
            name="recordVersion"
            type="com.pinncorp.framework.hibernate.UUIDType"
            column="recordVersion"
            access="property"
            unsaved-value="undefined"
        />

        <property
            name="userKey"
            type="int"
            update="true"
            insert="true"
            access="field"
            column="Store_Id"
            not-null="true"
        />

        <property
            name="shortDescription"
            type="java.lang.String"
            update="true"
            insert="true"
            access="field"
            column="Short_Description"
        />

        <property
            name="longDescription"
            type="java.lang.String"
            update="true"
            insert="true"
            access="field"
            column="Long_Description"
        />

        <property
            name="comment"
            type="java.lang.String"
            update="true"
            insert="true"
            access="field"
            column="Memo"
        />

        <property
            name="status"
            type="java.lang.String"
            update="true"
            insert="true"
            access="field"
            column="Status"
            not-null="true"
        />

        <property
            name="depositDateRange"
            type="int"
            update="true"
            insert="true"
            access="field"
            column="Deposit_Date_Range"
        />

        <property
            name="squareFootage"
            type="int"
            update="true"
            insert="true"
            access="field"
            column="Square_Footage"
        />

        <property
            name="MWSVersion"
            type="java.lang.String"
            update="true"
            insert="true"
            access="field"
            column="MWS_Version"
        />

        <property
            name="firstDayWithPaperwork"
            type="java.util.Date"
            update="true"
            insert="true"
            access="field"
            column="First_Day_Paperwork"
        />

        <property
            name="markDayAsAudited"
            type="boolean"
            update="true"
            insert="true"
            access="field"
            column="Mark_Day"
        />

        <property
            name="auditUserId"
            type="java.lang.String"
            update="true"
            insert="true"
            access="field"
            column="AUDIT_USER_ID"
        />

        <set
            name="macroValues"
            lazy="true"
            inverse="true"
            cascade="all-delete-orphan"
            sort="unsorted"
         access="field"
        >

              <key
                  column="Store_Target_Id"
              >
              </key>

              <one-to-many
                  class="com.pinncorp.sysmngr.store.macro.StoreTargetMacroValue"
              />

        </set>
    </class>
</hibernate-mapping>



@Entity mapped version of the Store class
Code:
@Entity
public class Store
{
    @Id @Column(name="I_STORE_ID") @GeneratedValue(generator="system-uid") @GenericGenerator(name="system-uid", strategy="uuid.hex")
    private String id;

    @Column(name="STORE_ID")
    private int userKey;

    @Column(name="SHORT_DESCRIPTION")
    private String shortDescription;

    @Column(name="LONG_DESCRIPTION")
    private String longDescription;

    @Column(name="MEMO")
    private String comment;

    @Column(name="DEPOSIT_DATE_RANGE")
    private int depositDateRange;

    @Column(name="SQUARE_FOOTAGE")
    private int squareFootage;

    @Column(name="MWS_VERSION")
    private String MWSVersion;

    @Temporal(TemporalType.DATE)
    @Column(name="FIRST_DAY_PAPERWORK")
    private Date firstDayWithPaperwork;

    @Column(name="MARK_DAY")
    private boolean markDayAsAudited = false;

    ....etc...
}



Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 26, 2006 5:27 pm 
Beginner
Beginner

Joined: Tue Aug 03, 2004 1:13 pm
Posts: 23
Well..I went back and retested the code and it seems to be working now. Not sure how as I didnt make any changes from when it wasnt.

I didt find another problem though )

If I have a @Entity mapped class reference a HBM mapped class from an @ManyToMany/ManyToOne the schema that gets generated using a binary blob for the FK ref to the other class (im assuming because it doesnt actually see it as a reference to an entity but as a Serializable type.)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 10:49 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
are you sure i've got a test case for that.
Which version are you using?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 10:54 am 
Beginner
Beginner

Joined: Tue Aug 03, 2004 1:13 pm
Posts: 23
hibernate 3.1
annotations 3.1-beta8
entitymanager 3.1-beta6


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 1:14 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://opensource.atlassian.com/projects/hibernate/browse/ANN-330

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 1:24 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
hug, wrong bug on the wrong topic

If you can reproduce it and make it happen in a small runnable test case then post it to JIRA

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 2:41 pm 
Beginner
Beginner

Joined: Tue Aug 03, 2004 1:13 pm
Posts: 23
Will do.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 6:51 pm 
Beginner
Beginner

Joined: Tue Aug 03, 2004 1:13 pm
Posts: 23
Issue created :

http://opensource.atlassian.com/projects/hibernate/browse/ANN-332


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