-->
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.  [ 3 posts ] 
Author Message
 Post subject: Re: Error trying to map embedded to secondary table [SOLVED]
PostPosted: Wed Jul 29, 2009 11:32 pm 
Newbie

Joined: Wed Jul 29, 2009 11:01 pm
Posts: 7
Hi there,

I have a peculiar problem with Hibernate JPA. I seem to be unable to put an embedded entity into a secondary table.

Here is a such an entity definition (put into orm.xml):
Code:
<entity class="example.Foo" name="Foo" access="PROPERTY">
    <table name="tbl_foo"/>
    <secondary-table name="tbl_foo_desc">
        <primary-key-join-column name="c_foo"/>
    </secondary-table>
    <secondary-table name="tbl_foo_bar">
        <primary-key-join-column name="c_foo"/>
    </secondary-table>
    <attributes>
        <id name="id">
            <column name="c_id" nullable="false" updatable="false"/>
            <generated-value strategy="TABLE" generator="Foo"/>
            <table-generator name="Foo"
                             table="tbl_jpa_seq_gen"
                             pk-column-name="c_entity"
                             value-column-name="c_count"
                             pk-column-value="Foo"/>
        </id>
        <basic name="name">
            <column name="c_name" length="255"/>
        </basic>
        <basic name="description" fetch="LAZY">
            <column name="c_description" table="tbl_foo_desc" length="65536"/>
        </basic>
        <embedded name="bar">
            <attribute-override name="info">
                <column name="c_info" table="tbl_foo_bar" nullable="false" updatable="false"/>
            </attribute-override>
            <attribute-override name="context">
                <column name="c_context" table="tbl_foo_bar" nullable="false" updatable="false"/>
            </attribute-override>
        </embedded>
    </attributes>
</entity>


And here is the definition of the embeddable in the same file:
Code:
<embeddable class="example.Bar" access="PROPERTY">
    <attributes>
        <basic name="info">
            <column name="c_info"/>
        </basic>
        <basic name="context">
            <column name="c_context"/>
        </basic>
    </attributes>
</embeddable>


When I try to deploy this I get the following error:

Quote:
Binding entity from annotated class: example.Foo
Bind entity example.Foo on table tbl_foo
Adding secondary table to entity example.Foo -> tbl_foo_desc
Adding secondary table to entity example.Foo -> tbl_foo_bar
A component cannot hold properties split into 2 different tables: example.Foo.bar
org.hibernate.AnnotationException: A component cannot hold properties split into 2 different tables: example.Foo.bar
<omitted stack trace>


Am I trying to do something that is not permitted? Any help would be much appreciated.

I am using Hibernate JPA 3.4.0 available via the Glassfish update center.


Last edited by clemenb on Fri Jul 31, 2009 4:47 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Error trying to map embedded to secondary table [SOLVED]
PostPosted: Fri Jul 31, 2009 4:47 pm 
Newbie

Joined: Wed Jul 29, 2009 11:01 pm
Posts: 7
It seems like the error was actually related to a bean property naming issue (foo and bar were not the properties in the actual code).

The offending bean fields and properties of the embeddable were:

mD5Sum -> (getMD5Sum and setMD5Sum)
sHA1Sum -> (getSHA1Sum and setSHA1Sum)

after changing them to:

md5Sum (getMd5Sum and setMd5Sum)
sha1Sum (getSha1Sum and setSha1Sum)

things just started working. Though I have no idea at the moment why that would be. Both definitions seem fine in respect to JavaBeans convention.


Top
 Profile  
 
 Post subject: Re: Error trying to map embedded to secondary table [SOLVED]
PostPosted: Thu Aug 20, 2009 3:56 am 
Newbie

Joined: Thu Aug 07, 2008 12:03 pm
Posts: 16
Hi, I've run into that problem too. And I don't think it has to do with those method's names.

Actually, the error shows up when you have duplicated property names in both, the "master" entity and the embedded class.

For instance, if you have the field "mD5Sum" in both the master and embedded class you must change one of them to another name.

When you changed those names it worked because they weren't duplicated anymore.

This is lame, though, Hibernate should handle that and I consider it a bug.


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