-->
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.  [ 6 posts ] 
Author Message
 Post subject: Multiple Composite attributes in one embedded class fails
PostPosted: Wed Mar 14, 2007 10:40 am 
Beginner
Beginner

Joined: Wed Jul 14, 2004 11:51 am
Posts: 43
Hello,

I'm currently refactoring my application to work with annotations but am encountering a problem when I have a class with 2 composite attributes in an embedded class:

Code:
@javax.persistence.Embeddable
@javax.persistence.MappedSuperclass
public class ArticleLocalization
        implements org.dataisland.primitives.bean.Localization, Serializable {
...

    private org.dataisland.primitives.datatype.Blob binaryContent;

@org.hibernate.annotations.Type(type="org.dataisland.primitives.hibernate.BlobHibernateType")
    @javax.persistence.Embedded
    @javax.persistence.AttributeOverrides( {
            @javax.persistence.AttributeOverride(name="content", column = @javax.persistence.Column(name="BINARY_CONTENT_CONTENT") ),
            @javax.persistence.AttributeOverride(name="contentType", column = @javax.persistence.Column(name="BINARY_CONTENT_CONTENTTYPE") ),
            @javax.persistence.AttributeOverride(name="contentFileName", column = @javax.persistence.Column(name="BINARY_CONTENT_FILENAME") )
    } )
    public org.dataisland.primitives.datatype.Blob getBinaryContent() {
        return this.binaryContent;
    }
    public void setBinaryContent(org.dataisland.primitives.datatype.Blob value) {
        this.binaryContent = value;
    }



    private org.dataisland.primitives.datatype.Blob representation;
    @org.hibernate.annotations.Type(type="org.dataisland.primitives.hibernate.BlobHibernateType")
    @javax.persistence.Embedded
    @javax.persistence.AttributeOverrides( {
            @javax.persistence.AttributeOverride(name="content", column = @javax.persistence.Column(name="REPRESENTATION_CONTENT") ),
            @javax.persistence.AttributeOverride(name="contentType", column = @javax.persistence.Column(name="REPRESENTATION_CONTENTTYPE") ),
            @javax.persistence.AttributeOverride(name="contentFileName", column = @javax.persistence.Column(name="REPRESENTATION_FILENAME") )
    } )
    public org.dataisland.primitives.datatype.Blob getRepresentation() {
        return this.representation;
    }
    public void setRepresentation(org.dataisland.primitives.datatype.Blob value) {
        this.representation = value;
    }


...
}


As you can see the class refers to two blobs which have different columns but (obviously) the same name.

Whey hibernate reads the mappings, I get this exception:

org.hibernate.MappingException: Repeated column in mapping for collection: ca.illi.article.closable.entities.ClosableArt
iclePlaceHolder.closableArticleSummaryLocalizations column: content

Does anyone know what I'm missing? If I remove one of the 2, it works fine. Seems to complain about columns being the same when the names are obviously different by my attribute overrides (?)

Any help would be greatly appreciated,

Thanks

François


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 14, 2007 7:28 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
First of all I cannot guaranty that @mappedSuperclass and @embeddable work well together on the same class
Second, you cannot use both @Type and @Embedded, choose one.

Apart from that it really should work, are you sure you don't have a typo in your property name?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 2:59 pm 
Beginner
Beginner

Joined: Wed Jul 14, 2004 11:51 am
Posts: 43
Hi Emmanuel,

Thanks for your reply. I removed the @mappedSuperclass from the class annotations and the @embedded on the "blob" attributes.

The good thing is that now my database is created without the mapping exception. Unfortunately, it brings another problem:

The reason I had used the @mappedSuperclass was because I wanted my subclass to "inherit" the properties of the embeddable object.

To better understand my need here are the entities I would like to create:

Article
-------
id: string

ArticleLocalization
---------------------
binaryContent: blob
representation: blob

ItemArticle (extends Article)
-------------
...(some attributes)

ItemArticleLocalization (extends ArticleLocalization)
--------------------------
...(other localized attributes)

ArticleLocalization is a mapped from article and is therefore an "embeddable" element.
ItemArticleLocalization is mapped from ItemArticle and is also an "embeddable" element.

Ideally, I would like the attributes not to be repeated in the ItemArticleLocalization table but I don't know how to do this. Otherwise, I could live with the fact of having the attributes in both the localized tables.

Right now, when I try to save any entity without the mappedsuperclass I get the following error:

Code:
java.lang.ExceptionInInitializerError
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
   at java.lang.reflect.Constructor.newInstance(Unknown Source)
   at java.lang.Class.newInstance0(Unknown Source)
   at java.lang.Class.newInstance(Unknown Source)
   at org.mdarad.global.dao.HibernateDAOFactoryBase.createDAO(HibernateDAOFactoryBase.java:678)
   at org.mdarad.global.dao.HibernateDAOFactoryBase.getCommentDAO(HibernateDAOFactoryBase.java:568)
   at org.mdarad.samples.totaltest.facades.CommentBusinessObjectFacadeBase.getInstanceDAO(CommentBusinessObjectFacadeBase.java:39)
   at org.mdarad.samples.totaltest.facades.CommentBusinessObjectFacadeBase.saveComment(CommentBusinessObjectFacadeBase.java:66)
   at org.mdarad.samples.totaltest.unittests.AbstractCommentTestCase.createMinimalComment(AbstractCommentTestCase.java:20)
   at org.mdarad.samples.totaltest.unittests.CommentTestCase.testCreateMinimal(CommentTestCase.java:40)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
   at org.hibernate.persister.collection.AbstractCollectionPersister.generateSelectSizeString(AbstractCollectionPersister.java:867)
   at org.hibernate.persister.collection.AbstractCollectionPersister.<init>(AbstractCollectionPersister.java:475)
   at org.hibernate.persister.collection.BasicCollectionPersister.<init>(BasicCollectionPersister.java:50)
   at org.hibernate.persister.PersisterFactory.createCollectionPersister(PersisterFactory.java:72)
   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:250)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
   at org.mdarad.framework.business.dao.HibernateDAO.<clinit>(HibernateDAO.java:30)
   ... 28 more



I used to be able to do this without the annotations (repeated attributes though) but can't seem to accomplish it with the annotations.

Your help would be greatly appreciated.

Thanks again,

François


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 9:10 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I understand, but so far I do not support @MappedSuperclass and @Embeddable, there is an open JIRA issue, but I haven't had time so far to have a look at it. The fastest way would be to have a patch contribution, but I reckon it might not be super easy.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 9:12 am 
Beginner
Beginner

Joined: Wed Jul 14, 2004 11:51 am
Posts: 43
Ok thanks a lot Emmanuel. At least I know I can stop playing around with my mappings (I really turned them upside down).

What would you suggest as a workaround? That I duplicate all the fields and mapping from the superclass to the subclass?

Thanks,

François


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 10:30 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
that or use an xml mapping

_________________
Emmanuel


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