[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Problem cloning entity with ClassMetadata

terryb do-not-reply at jboss.com
Sat Jul 19 10:30:29 EDT 2008


I am attempting to write a utility method to clone an entity using Hibernate ClassMetadata. my entities extend a EntityBase class which holds few common properties and methods. The problem is that the classMetadata.getPropertyValues(...) method throws exception when it tries to access getter method for property defined in the superclass. 

Any way to resolve this????

Exception


  | Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of au.edu.tisc.entity.EntityBase.insertDate 
  | 
  | Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of au.edu.tisc.entity.EntityBase.insertDate
  | 
  |   at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
  |   at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValues(AbstractEntityTuplizer.java:256)
  |   at org.hibernate.tuple.entity.PojoEntityTuplizer.getPropertyValues(PojoEntityTuplizer.java:209)
  |   at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValues(AbstractEntityPersister.java:3576)
  |   at au.edu.tisc.session.CloneEntity.clone(EntityCloner.java:48)
  |   ....
  |   ....
  | 


  | Snippet from my EntitCloner utility class	
  | 
  | ...
  | ClassMetadata classMetadata = sessionFactory.getClassMetadata(course.getClass());
  |     	
  | String[] propertyNames = classMetadata.getPropertyNames();
  | /* this works ok and lists all the properties, including those in the EntityBase(mappedSuperclass), as below: */
  | [insertDate,lastUpdateDate,code...]
  |     	
  |     	
  | Object[] propertyValues = classMetadata.getPropertyValues(this.sourceEntityClass, EntityMode.POJO);
  | /* this throws exception ?????????? as it tries to find/access/trace/? getter method for insertDate property */
  | ...
  | 
  | 
  | @Entity
  | @Table(name = "Course")
  | public class Course extends EntityBase implements java.io.Serializable {
  | 
  | 	private String code;
  | 	private CourseStatus courseStatus;
  | 	private Set<Preference> preferences = new HashSet<Preference>(0);	
  | 	...
  | 
  | 	public Course() {}
  | 	
  | 	public Course(String id, String code, CourseStatus courseStatus, Date lastUpdateDate, Date insertDate, Set<Preference> preferences ...) {
  | 		
  | 		super(id, lastUpdateDate, insertDate);
  | 		this.courseStatus = courseStatus;
  | 		this.code = code;
  | 		this.preferences = preferences;
  | 		...
  | 	}
  | 
  | 	@Column(name = "Code", nullable = false, length = 20)
  | 	@NotNull
  | 	@Length(min = 5, max = 5)
  | 	public String getCode() {
  | 		return this.code;
  | 	}
  | 
  | 	public void setCode(String code) {
  | 		this.code = code;
  | 	}
  | 
  | 	@ManyToOne(fetch = FetchType.LAZY)
  | 	@JoinColumn(name = "CourseStatusID")
  | 	public CourseStatus getCourseStatus() {
  | 		return this.courseStatus;
  | 	}
  | 
  | 	public void setCourseStatus(CourseStatus courseStatus) {
  | 		this.courseStatus = courseStatus;
  | 	}
  | 	
  | 	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "course")
  | 	public Set<Preference> getPreferences() {
  | 		return this.preferences;
  | 	}
  | 
  | 	public void setPreferences(Set<Preference> preferences) {
  | 		this.preferences = preferences;
  | 	}	
  | 	...
  | }	
  | 
  | 
  | @MappedSuperclass
  | public abstract class EntityBase {
  |     private String id;
  |     private Date lastUpdateDate;
  |     private Date insertDate;
  | 
  |     public EntityBase () {
  |         super();
  |     }
  | 
  |     public EntityBase (String id) {
  |         super();
  |         this.id = id;
  |     }
  | 
  |     public EntityBase(String id, Date lastUpdateDate, Date insertDate) {
  |         super();
  |         this.id = id;
  |         this.lastUpdateDate = lastUpdateDate;
  |         this.insertDate = insertDate;
  |     }
  | 
  |     @Id
  |     @GenericGenerator(strategy="au.edu.tisc.session.OnlineKeyGenerator", name="onlineKeyGen")
  |     @GeneratedValue(generator="onlineKeyGen")
  |     @Column(name = "ID", unique = true, nullable = false, length = 20)
  |     public String getId() {
  |         return id;
  |     }
  | 
  |     public void setId(String id) {
  |         this.id = id;
  |     }
  | 
  |     @Column(name = "LastUpdateDate", length = 23)
  |     public Date getLastUpdateDate() {
  |         return lastUpdateDate;
  |     }
  | 
  |     public void setLastUpdateDate(Date lastUpdateDate) {
  |         this.lastUpdateDate = lastUpdateDate;
  |     }
  | 
  |     @Column(name = "InsertDate", length = 23)
  |     public Date getInsertDate() {
  |         return insertDate;
  |     }
  | 
  |     public void setInsertDate(Date insertDate) {
  |         this.insertDate = insertDate;
  |     }
  |     ...
  | }
  | 

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

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



More information about the jboss-user mailing list