-->
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.  [ 4 posts ] 
Author Message
 Post subject: Trouble with @Embedded List<>
PostPosted: Thu Oct 19, 2006 9:26 am 
Newbie

Joined: Thu Oct 19, 2006 9:11 am
Posts: 3
Hi all,

I have scoured the forums and the documentation to no avail. Maybe someone can point me at the document that I missed, or if it's a simple, silly mistake point me in the right direction. Thanks!

I am implementing an application using the new EJB3 / Hibernate Annotations peristence mechanisms. To this end I have written a model and a set of templates using the MDSD tool 'openArchitectureWare', which generates my set of EJB3 entities, TOs and facades, complete with annotations, and ready to deploy.

One of the use cases that I am testing involves a List of embedded objects in an entity. The embedded object itsself also contains an embedded List of strings.
Code:
SimpleEntity ----------> List<SimpleEmbedded> ---------> List<String>
The code compiles fine but when I deploy I get a very strange error message:
java.lang.UnsupportedOperationException: one-to-one is not supported here


If I make either of the aggregations single cardinality then the entity seems to deploy normally!
- single embedded object in an entity, embedded object has a List of strings
- List of embedded objects in an entity, embedded object has no List.
It is only when both the embedded object is a List and itsself has a List of strings that I get the strange error.

There is no business functionality in the entity or the embedded object - they are both simple pojos.

Here's the code:

Entity:

Code:
package ch.adamcc.planeres2.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.Id;

import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.IndexColumn;

@Entity
public class SimpleEntity {
    private long _id;
    private String _stringField;
    private List<String> _stringList;
    private long[] _longArray;
   
    @Embedded
    private List<SimpleEmbedded> _simpleEmbeddedList;

    public SimpleEntity()
    {
       this._stringList = new ArrayList<String>();
       this._longArray = new long[2];
       
       this._simpleEmbeddedList = new ArrayList<SimpleEmbedded>();
    }
   
    @Id
    public long getId() {
       return this._id;
    }

    public void setId(long id) {
       this._id = id;
    }
   
    public String getStringField() {
       return this._stringField;
    }

    public void setStringField(String stringField) {
       this._stringField = stringField;
    }

    @CollectionOfElements
    public List<String> getStringList() {
       return this._stringList;
    }
   
    public void setStringList(List<String> stringList) {
       this._stringList = stringList;
    }

    @CollectionOfElements
    @IndexColumn(name="longArray_index")
    public long[] getLongArray() {
       return this._longArray;
    }

    public void setLongArray(long[] longArray) {
       this._longArray = longArray;
    }
   
    @CollectionOfElements
    public List<SimpleEmbedded> getSimpleEmbeddedList() {
       return _simpleEmbeddedList;
    }


    public void setSimpleEmbeddedList(List<SimpleEmbedded> simpleEmbeddedList) {
       this._simpleEmbeddedList = simpleEmbeddedList;
    }
}


Embedded:

Code:
package ch.adamcc.planeres2.entity;

import org.hibernate.annotations.CollectionOfElements;

import java.io.Serializable;
import java.lang.String;
import java.util.List;
import javax.persistence.Embeddable;
import javax.persistence.Embedded;

@Embeddable
public class SimpleEmbedded implements Serializable {
    private String _embeddedStringField;
    private boolean _embeddedBooleanField;
    @Embedded
    private List<String> _embeddedStringList;

    public SimpleEmbedded() {
    }

    public SimpleEmbedded(String embeddedStringField, boolean embeddedBooleanField, List<String> embeddedStringList) {
        this._embeddedStringField = embeddedStringField;
        this._embeddedBooleanField = embeddedBooleanField;
        this._embeddedStringList = embeddedStringList;
    }

    public String getEmbeddedStringField() {
        return this._embeddedStringField;
    }

    public void setEmbeddedStringField(String embeddedStringField) {
        this._embeddedStringField = embeddedStringField;
    }

    public boolean getEmbeddedBooleanField() {
        return this._embeddedBooleanField;
    }

    public void setEmbeddedBooleanField(boolean embeddedBooleanField) {
        this._embeddedBooleanField = embeddedBooleanField;
    }

    @CollectionOfElements
    public List<String> getEmbeddedStringList() {
        return this._embeddedStringList;
    }

    public void setEmbeddedStringList(List<String> embeddedStringList) {
        this._embeddedStringList = embeddedStringList;
    }
}


Error output:

Code:
17:28:10,627 WARN  [ServiceController] Problem starting service persistence.units:ear=planeres2.ear,
jar=planeres2.jar,unitName=planeres2-persistence-unit
javax.persistence.PersistenceException: org.hibernate.MappingException: bug in initComponentProperty
Paths
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:695)
   at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.
java:127)
   at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:264)
   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 org.jboss.ejb3.ServiceDelegateWrapper.startService(ServiceDelegateWrapper.java:102)
   at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
   at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
   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 org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
   at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
   at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
   at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
   at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
   at $Proxy0.start(Unknown Source)
   at org.jboss.system.ServiceController.start(ServiceController.java:417)
   at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
   at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
   at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
   at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
   at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
   at $Proxy69.start(Unknown Source)
   at org.jboss.ejb3.JmxKernelAbstraction.install(JmxKernelAbstraction.java:96)
   at org.jboss.ejb3.Ejb3Deployment.startPersistenceUnits(Ejb3Deployment.java:467)
   at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:317)
   at org.jboss.ejb3.Ejb3Module.startService(Ejb3Module.java:91)
   at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
   at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
   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 org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
   at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
   at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
   at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
   at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
   at $Proxy0.start(Unknown Source)
   at org.jboss.system.ServiceController.start(ServiceController.java:417)
   at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
   at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
   at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
   at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
   at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
   at $Proxy34.start(Unknown Source)
   at org.jboss.ejb3.EJB3Deployer.start(EJB3Deployer.java:449)
   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 org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
   at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
   at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
   at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
   at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.ja
va:142)
   at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
   at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:2
38)
   at org.jboss.ws.server.WebServiceDeployer.start(WebServiceDeployer.java:117)
   at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerIntercepto
rSupport.java:188)
   at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
   at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
   at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
   at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
   at $Proxy35.start(Unknown Source)
   at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1007)
   at org.jboss.deployment.MainDeployer.start(MainDeployer.java:997)
   at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:808)
   at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:771)
   at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
   at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
   at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
   at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
   at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.ja
va:142)
   at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
   at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
   at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
   at $Proxy6.deploy(Unknown Source)
   at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
   at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:610)
   at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentSc
anner.java:263)
   at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScan
ner.java:274)
   at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScann
er.java:225)
Caused by: org.hibernate.MappingException: bug in initComponentPropertyPaths
   at org.hibernate.persister.entity.AbstractPropertyMapping.initComponentPropertyPaths(AbstractProper
tyMapping.java:208)
   at org.hibernate.persister.collection.CompositeElementPropertyMapping.<init>(CompositeElementPropertyMapping.java:26)
   at org.hibernate.persister.collection.AbstractCollectionPersister.<init>(AbstractCollectionPersister.java:496)
   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:1218)
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:688)
   ... 101 more
Caused by: java.lang.UnsupportedOperationException: one-to-one is not supported here
   at org.hibernate.persister.entity.AbstractPropertyMapping.getIdentifierColumnNames(AbstractProperty
Mapping.java:30)
   at org.hibernate.persister.entity.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping
.java:131)
   at org.hibernate.persister.entity.AbstractPropertyMapping.initComponentPropertyPaths(AbstractProper
tyMapping.java:204)
   ... 108 more



I apologise for the code spam.

I like the idea of using embedded objects because it reduces the granularity of the entity interface which is a Good Thing. What am I doing wrong? Should I just give up and use associations instead? (ie @OneToMany)

Thanks very much in advance for your answer.

Yours,

Adam Crowther


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 30, 2006 6:25 pm 
Newbie

Joined: Thu Sep 28, 2006 6:01 pm
Posts: 8
Location: Colorado, USA
I am having exactly the same problem. @Embeddable objects that themselves contain Collections of other @Embeddable objects don't work in Hibernate (with Annotations, anyhow). Why? It seems like the type of thing could automatically inferred.

This can't be that rare of a code structure.

Thanks,
Sean


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 30, 2006 7:58 pm 
Newbie

Joined: Thu Sep 28, 2006 6:01 pm
Posts: 8
Location: Colorado, USA
I think this comment from the Hibernate DTD answers the question:

Quote:
<!-- A composite element allows a collection to hold instances of an arbitrary
class, without the requirement of joining to an entity table. Composite elements
have component semantics - no shared references and ad hoc null value semantics.
Composite elements may not hold nested collections. -->


"Composite Elements" are the same as @Embeddable objects. So, it is not possible for a collection of @Embeddable objects to hold collections. They must be promoted to @Entity objects. *sigh*


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 2:23 am 
Newbie

Joined: Thu Oct 19, 2006 9:11 am
Posts: 3
Hi Sean,

Thanks very much for finding that and posting it - I missed it entirely.

Back to the drawing board.

Yours,

Adam.


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