[jboss-user] [EJB 3.0] - Trouble with @Embedded List<>

adamcc do-not-reply at jboss.com
Wed Oct 18 12:04:34 EDT 2006


Hello again,

Please forgive the newbie post again - again I have scoured the forums and the documentation to no avail.

I am still trying to implement 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.  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:

  | 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:

  | 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:

  | 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 initComponentPropertyPaths 
  | 	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.java:142)
  | 	at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
  | 	at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
  | 	at org.jboss.ws.server.WebServiceDeployer.start(WebServiceDeployer.java:117)
  | 	at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.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.java: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(AbstractDeploymentScanner.java:263)
  | 	at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:274)
  | 	at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:225)
  | Caused by: org.hibernate.MappingException: bug in initComponentPropertyPaths
  | 	at org.hibernate.persister.entity.AbstractPropertyMapping.initComponentPropertyPaths(AbstractPropertyMapping.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(AbstractPropertyMapping.java:30)
  | 	at org.hibernate.persister.entity.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:131)
  | 	at org.hibernate.persister.entity.AbstractPropertyMapping.initComponentPropertyPaths(AbstractPropertyMapping.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)  

Again, thanks very much in advance for your answer.

Yours,

Adam Crowther

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3979134#3979134

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3979134



More information about the jboss-user mailing list