Hi guys,
I am new to hibernate and having hard time for mapping two entities.
I am building the application under Seam 2.1 + JBoss AS 5.0.0.GA
I am using hibernate as JPA provider by default in Seam 2.1 project.
Database is MS SQL 2005.
Code:
@Entity
@Table(name="UserClinicalData")
public class MeasurementData implements Serializable
{
private Long id;
private Long clinicalDataId;
private Date addDateTime;
private Date voidedDateTime;
private float valueNumeric;
// Associated Entities
private Patient patient;
@Id @GeneratedValue
@Column(name="Id")
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
@Column(name="ClinicalDataId", nullable=false)
public void setClinicalDataId(Long clinicalDataId) { this.clinicalDataId = clinicalDataId; }
public Long getClinicalDataId() { return clinicalDataId; }
@Column(name="AddDateTime")
public void setAddDateTime(Date addDateTime) { this.addDateTime = addDateTime; }
public Date getAddDateTime() { return addDateTime; }
@Column(name="VoidedDateTime")
public void setVoidedDateTime(Date voidedDateTime) { this.voidedDateTime = voidedDateTime; }
public Date getVoidedDateTime() { return voidedDateTime; }
@Column(name="ValueNumeric")
public void setValueNumeric(float valueNumeric) { this.valueNumeric = valueNumeric; }
public float getValueNumeric() { return valueNumeric; }
/*** problem occurred here ***/
@ManyToOne(targetEntity=Patient.class)
@JoinColumn(name="UserId", nullable=false)
public void setPatient(Patient patient) { this.patient = patient; }
public Patient getPatient() { return patient; }
}
Code:
@Entity
@Table(name="[User]", schema="dbo", catalog="TMS_20080307")
public class Patient implements Serializable
{
private String id;
private Date birthDate;
private List<MeasurementData> measurementData = new ArrayList<MeasurementData>();
@Id @GeneratedValue
@Column(name="Id")
public String getId() { return id; }
public void setId(String id) { this.id = id; }
@Column(name="BirthDate")
public void setBirthDate(Date birthDate) { this.birthDate = birthDate; }
public Date getBirthDate() { return birthDate; }
/*** problem occurred here ***/
@OneToMany(mappedBy="patient", cascade=CascadeType.ALL)
public void setMeasurementData(List<MeasurementData> measurementData) { this.measurementData = measurementData; }
public List<MeasurementData> getMeasurementData() { return measurementData; }
}
I have been given the following exception when unit test on TestNG:
Code:
ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] Error installing to Start: name=persistence.units:unitName=dss state=Create
javax.persistence.PersistenceException: org.hibernate.MappingException: Could not determine type for: java.util.List, for columns: [org.hibernate.mapping.Column(measurementData)]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:663)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:127)
at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:259)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:56)
at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:110)
at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66)
at org.jboss.kernel.plugins.dependency.KernelControllerContextAction$JoinpointDispatchWrapper.execute(KernelControllerContextAction.java:214)
at org.jboss.kernel.plugins.dependency.ExecutionWrapper.execute(ExecutionWrapper.java:45)
at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchExecutionWrapper(KernelControllerContextAction.java:108)
at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchJoinPoint(KernelControllerContextAction.java:69)
at org.jboss.kernel.plugins.dependency.LifecycleAction.installActionInternal(LifecycleAction.java:221)
at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.installAction(KernelControllerContextAction.java:135)
at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.installAction(KernelControllerContextAction.java:46)
at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:327)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1309)
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:734)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:862)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:784)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:574)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:398)
at org.jboss.kernel.plugins.dependency.AbstractKernelController.install(AbstractKernelController.java:96)
at org.jboss.kernel.plugins.dependency.AbstractKernelController.install(AbstractKernelController.java:90)
at org.jboss.ejb3.MCKernelAbstraction.install(MCKernelAbstraction.java:151)
at org.jboss.ejb3.Ejb3Deployment.startPersistenceUnits(Ejb3Deployment.java:604)
at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:400)
at org.jboss.ejb3.deployers.EJBStage2Deployer.deploy(EJBStage2Deployer.java:53)
at org.jboss.ejb3.deployers.EJBStage2Deployer.deploy(EJBStage2Deployer.java:37)
at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:65)
at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:169)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:853)
at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:794)
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:327)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1309)
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:734)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:862)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:784)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:622)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:411)
at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:498)
at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:506)
at org.jboss.embedded.DeploymentGroup.process(DeploymentGroup.java:127)
at org.jboss.embedded.Bootstrap.deployResourceBases(Bootstrap.java:289)
at org.jboss.seam.mock.EmbeddedBootstrap.startAndDeployResources(EmbeddedBootstrap.java:15)
at org.jboss.seam.mock.AbstractSeamTest.startJbossEmbeddedIfNecessary(AbstractSeamTest.java:1024)
at org.jboss.seam.mock.AbstractSeamTest.startSeam(AbstractSeamTest.java:915)
at org.jboss.seam.mock.SeamTest.startSeam(SeamTest.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:607)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:417)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:154)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:88)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:284)
at org.testng.SuiteRunner.run(SuiteRunner.java:204)
at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:877)
at org.testng.TestNG.runSuitesLocally(TestNG.java:842)
at org.testng.TestNG.run(TestNG.java:751)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:124)
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, for columns: [org.hibernate.mapping.Column(measurementData)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
at org.hibernate.mapping.Property.isValid(Property.java:185)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:440)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:918)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:656)
... 68 more
Will the naming of Entity class cause the problem?? Both entities are quite simple, I couldn't think of anywhere else.
Appreciated any help. :)