-->
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.  [ 5 posts ] 
Author Message
 Post subject: Need help mapping a collection of embedded objects?
PostPosted: Fri Jun 12, 2009 11:20 pm 
Regular
Regular

Joined: Tue Jul 29, 2008 4:15 pm
Posts: 62
Location: Dallas, TX US
Hello all,

I need help mapping a collection of embedded objects. I have a Person class that implements a Person interface and has a one to many relationship to my EmailAddress class that also impments a EmailAddress interface. Both of these classes extends a Base class that is annotated with @MappedSuperclass. I emphasize the exists of the interfaces because I think it has something to do with my problem. I get the following error (see below) when I try to execute a test.

Please help get me off on the write track.

Thanks!

Code:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'annotatedSessionFactory' defined in class path resource [com/aviall/edi/jedi/persistence/core/dao/systest/PersonDaoTest.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: person, for columns: [org.hibernate.mapping.Column(email_addresses)]
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
   at java.security.AccessController.doPrivileged(Native Method)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
   at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
   at com.aviall.edi.jedi.persistence.core.dao.systest.PersonDaoTest.<init>(PersonDaoTest.java:33)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
   at org.junit.internal.runners.JUnit4ClassRunner.createTest(JUnit4ClassRunner.java:72)
   at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:79)
   at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
   at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
   at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
   at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
   at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
   at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:36)
   at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
   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: org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: person, for columns: [org.hibernate.mapping.Column(email_addresses)]
   at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:292)
   at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:276)
   at org.hibernate.mapping.Property.isValid(Property.java:207)
   at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:458)
   at org.hibernate.mapping.RootClass.validate(RootClass.java:215)
   at org.hibernate.cfg.Configuration.validate(Configuration.java:1135)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1320)
   at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
   at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:805)
   at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:745)
   at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
   ... 34 more

_________________
pouncilt


Top
 Profile  
 
 Post subject: Re: Need help mapping a collection of embedded objects?
PostPosted: Fri Jun 12, 2009 11:24 pm 
Regular
Regular

Joined: Tue Jul 29, 2008 4:15 pm
Posts: 62
Location: Dallas, TX US
<b>BasePersistableModel.java:</b>
Code:
package com.aviall.edi.jedi.persistence.commons.models;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.aviall.commons.domain.model.api.Persistable;

@MappedSuperclass
public class BasePersistableModel implements Persistable<Object> {
   @Column(name="CREATED_BY", nullable=false)
   private String createdBy;
   @Column(name="UPDATED_BY", nullable=false)
   private String updatedBy;
   @Column(name="CREATED_DATE", nullable=false, updatable=false, insertable=false)
   @org.hibernate.annotations.Generated(org.hibernate.annotations.GenerationTime.ALWAYS)
   @Temporal(TemporalType.TIMESTAMP)
   private Date createdDate;
   @Column(name="UPDATED_DATE", nullable=false, updatable=false, insertable=false)
   @org.hibernate.annotations.Generated(org.hibernate.annotations.GenerationTime.ALWAYS)
   @Temporal(TemporalType.TIMESTAMP)
   private Date updatedDate;
   
   
   public BasePersistableModel(){
      
   }
   
   public BasePersistableModel(String createdBy, Date createdDate, String updatedBy, Date updatedDate){
      this.createdBy = createdBy;
      this.createdDate = createdDate;
      this.updatedBy = updatedBy;
      this.updatedDate = updatedDate;
   }
   
   
   public String getCreatedBy() {
      return createdBy;
   }

   public void setCreatedBy(String createdBy) {
      this.createdBy = createdBy;
   }   

   public String getUpdatedBy() {
      return updatedBy;
   }
   
   public void setUpdatedBy(String updatedBy) {
      this.updatedBy = updatedBy;
   }
   
   public Date getCreatedDate() {
      return createdDate;
   }
   
   public void setCreatedDate(Date createdDate) {
      this.createdDate = createdDate;
   }
   
   public Date getUpdatedDate() {
      return updatedDate;
   }
   
   public void setUpdatedDate(Date updatedDate) {
      this.updatedDate = updatedDate;
   }
}



<b>BaseEntityModel.java:</b>
Code:
package com.aviall.edi.jedi.persistence.commons.models;

import java.util.Date;

import javax.persistence.*;

import com.aviall.commons.domain.model.api.Entity;

@MappedSuperclass
public abstract class BaseEntityModel extends BasePersistableModel implements Entity<Object>{      
   protected Long id;
   
   public BaseEntityModel(){
      super();
   }
   
   public BaseEntityModel(String createdBy, Date createdDate, String updatedBy, Date updatedDate){
      super(createdBy, createdDate, updatedBy, updatedDate);
   }
   
   private void setId(Long id) {
      this.id = id;
   }
}

_________________
pouncilt


Top
 Profile  
 
 Post subject: Re: Need help mapping a collection of embedded objects?
PostPosted: Fri Jun 12, 2009 11:25 pm 
Regular
Regular

Joined: Tue Jul 29, 2008 4:15 pm
Posts: 62
Location: Dallas, TX US
<b>EmailAddressHibernateVO.java:</b>
Code:
package com.aviall.edi.jedi.persistence.commons.vo.hibernate;

import java.util.Date;

import javax.persistence.*;

import com.aviall.commons.vo.model.api.IEmailAddressVO;
import com.aviall.edi.jedi.persistence.commons.models.BasePersistableModel;

@Embeddable
public class EmailAddressHibernateVO extends BasePersistableModel implements IEmailAddressVO {
   private static final long serialVersionUID = 1L;
   @Column(length=50, nullable=false)
   private String emailAddress;
   @Column(length=100, nullable=false)
   private String emailType;
   
   
   
   @SuppressWarnings("unused")
   private EmailAddressHibernateVO() {
      super();
      // TODO Auto-generated constructor stub
   }

   public EmailAddressHibernateVO(String emailAddress, String emailType, String createdBy, Date createdDate,
         String updatedBy, Date updatedDate) {
      super(createdBy, createdDate, updatedBy, updatedDate);
      this.emailAddress = emailAddress;
      this.emailType = emailType;
   }

   @Override
   public String getEmailAddress() {
      return emailAddress;
   }

   @Override
   public String getEmailType() {
      return emailType;
   }   
}


<b>PersonHibernateVO.java:</b>
Code:
package com.aviall.edi.jedi.persistence.commons.vo.hibernate;

import static javax.persistence.GenerationType.SEQUENCE;

import java.util.Date;
import java.util.Set;

import javax.persistence.*;


import com.aviall.commons.vo.model.api.IEmailAddressVO;
import com.aviall.commons.vo.model.api.IPersonVO;
import com.aviall.edi.jedi.persistence.commons.models.BaseEntityModel;

@javax.persistence.Entity
@AttributeOverride(name = "id", column = @Column(name = "PERSON_ID", nullable = false))
@Table(name = "Person")
@NamedQueries( {
      @NamedQuery(name = "Person.findByFirstName", query = "select p from Person p where p.firstName = ?"),
      @NamedQuery(name = "Person.findByLastName", query = "select p from Person p where p.lastName = ?") })
public class PersonHibernateVO extends BaseEntityModel implements IPersonVO {
   private static final long serialVersionUID = 1L;   
   @Column(name = "FIRST_NAME", nullable = false, length = 100)
   private String firstName;
   @Column(name = "MIDDLE_NAME", nullable = false, length = 100)
   private String middleName;
   @Column(name = "LAST_NAME", nullable = false, length = 100)
   private String lastName;

   @org.hibernate.annotations.CollectionOfElements(
      targetElement = com.aviall.commons.vo.model.api.IEmailAddressVO.class
   )
   @JoinTable(name = "PERSON_EMAIL_ADDRESS", joinColumns = @JoinColumn(name = "PERSON_ID"))
   private Set<IEmailAddressVO> emailAddresses;

   @SuppressWarnings("unused")
   private PersonHibernateVO(){}
   
   public PersonHibernateVO(String firstName, String middleName,
         String lastName, Set<IEmailAddressVO> emailAddresses,
         String createdBy, Date createdDate, String updatedBy,
         Date updatedDate) {
      super(createdBy, createdDate, updatedBy, updatedDate);
      this.firstName = firstName;
      this.middleName = middleName;
      this.lastName = lastName;
      this.emailAddresses = emailAddresses;
   }
   
   @SequenceGenerator(name = "generator", sequenceName = "PERSON_SEQ")
   @Id @GeneratedValue(strategy=SEQUENCE, generator="generator")
   @Column(name="ID", nullable=false, updatable=false, insertable=false)
   public Long getId(){
      return super.id;
   }

   @Override
   public String getFirstName() {
      return firstName;
   }

   @Override
   public String getLastName() {
      return lastName;
   }

   @Override
   public String getMiddleName() {
      return middleName;
   }

   @Override
   public void setFirstName(String firstName) {
      this.firstName = firstName;
   }

   @Override
   public void setLastName(String lastName) {
      this.lastName = lastName;
   }

   @Override
   public void setMiddleName(String middleName) {
      this.middleName = middleName;
   }

   @Override
   public Set<IEmailAddressVO> getEmailAddresses() {
      return emailAddresses;
   }

   @Override
   public void setEmailAddresses(Set<IEmailAddressVO> emailAddresses) {
      this.emailAddresses.clear();
      this.emailAddresses.addAll(emailAddresses);

   }
}

_________________
pouncilt


Top
 Profile  
 
 Post subject: Re: Need help mapping a collection of embedded objects?
PostPosted: Mon Jun 15, 2009 11:18 am 
Regular
Regular

Joined: Tue Jul 29, 2008 4:15 pm
Posts: 62
Location: Dallas, TX US
Does anybody have a clue to what is going here with my code? Why do I get the above exception? Should I remove my code from the post because it too hard to follow?

Any reply to my post is much appreciated.

Thanks!

_________________
pouncilt


Top
 Profile  
 
 Post subject: Re: Need help mapping a collection of embedded objects?
PostPosted: Sat Jun 20, 2009 10:27 am 
Regular
Regular

Joined: Tue Jul 29, 2008 4:15 pm
Posts: 62
Location: Dallas, TX US
My problems went away when I moved my id attributes and setter/getter methods inside the PersonHibernateVO class. Not sure why it didn't work inside the super class, but I am guessing it one of two things. One I didn't have the Super Class configured as an annotated class some where is my configuration. Or two, there was a hibernate didn't not like they way I annotated the id in both the super class and the subclass.

Thanks!

_________________
pouncilt


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