-->
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.  [ 2 posts ] 
Author Message
 Post subject: Object Model problem.
PostPosted: Sat Jan 28, 2006 1:57 pm 
Newbie

Joined: Sat Jan 28, 2006 1:10 pm
Posts: 6
Hi All,
Need your advice on the problem that I have. I am using XDoclet to generate the Hibernate mappings.

My object model-- I have a User, Project, Role objects. The User's role is qualified with a project, so I have composite object ProjectRole consistiing of a Project and Role and the user object contains a one-to-many collection of ProjectRoles.

------------------- User.java--------------------------------
public class User extends BaseObject implements Serializable {
private static final long serialVersionUID = 3832626162173359411L;

private Integer id;
protected String username;
protected String password;
protected String confirmPassword;
protected String firstName;
protected String lastName;
protected Address address = new Address();
protected String phoneNumber;
protected String email;
protected String website;
protected String passwordHint;
protected Integer version;
protected Boolean superAdmin;
protected Boolean enabled;
protected Set projectRoles = new HashSet();

public User() {
}

public User(String username) {
this.username = username;
}

....
.....
/**
* Returns the user's roles for different projects
*
* @return Set
*
* @hibernate.set table="user_project_role" cascade="save-update" lazy="false"
* @hibernate.collection-key column="user_id"
* @hibernate.collection-one-to-many class="com.testing.model.ProjectRole"
*/
public Set getProjectRoles()
{
return projectRoles;
}

public void setProjectRoles(Set projectRoles)
{
this.projectRoles = projectRoles;
}

}

------------------------------------------------------------------------------
------------------------ ProjectRole.java----------------------------------
public class ProjectRole extends BaseObject implements Comparable, Serializable
{
protected Integer id;
protected Project project;
protected Role role;

/**
* Returns the id.
* @return Integer
*
* @hibernate.id column="id"
* generator-class="increment" unsaved-value="null"
*/
public Integer getId() {
return id;
}

/**
* Sets the id.
* @param id The id to set
*/
public void setId(Integer id) {
this.id = id;
}

/**
* @hibernate.property column="project_id" type="integer" not-null="true"
*
* @return project
*/
public Project getProject()
{
return project;
}

public void setProject(Project project)
{
this.project = project;
}

/**
* @hibernate.property column="role_id" type="integer" not-null="true"
*/
public Role getRole()
{
return role;
}

public void setRole(Role role)
{
this.role = role;
}

}
-----------------------------------------------------------------------------------

The schema generated is

CREATE TABLE user_project_role
(
id int4 NOT NULL,
project_id int4 NOT NULL,
role_id int4 NOT NULL,
user_id int4,
CONSTRAINT user_project_role_pkey PRIMARY KEY (id),
CONSTRAINT fkf51d35d0917bfc13 FOREIGN KEY (user_id)
REFERENCES app_user (uid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)

Which is sort of what I want ... except that there are no foreign key constraints on the user_project_role table for the user_id and role_id columns tying them back to the project and role tables

I think that is the reason that I am seeing the following exception while running some tests..

[junit] Testcase: testGetUser(com.testing.dao.UserDAOTest): Caused an ERROR
[junit] exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.testing.model.ProjectRole.setProject; nested exception is org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.testing.model.ProjectRole.setProject
[junit] org.springframework.orm.hibernate3.HibernateSystemException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.testing.model.ProjectRole.setProject; nested exception is org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.testing.model.ProjectRole.setProject
[junit] org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.testing.model.ProjectRole.setProject
[junit] at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:203)
[junit] at org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:173)
[junit] at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2919)
[junit] at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
[junit] at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:530)
[junit] at org.hibernate.loader.Loader.doQuery(Loader.java:436)
[junit] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
[junit] at org.hibernate.loader.Loader.loadCollection(Loader.java:1434)
[junit] at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:111)
[junit] at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488)
[junit] at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
[junit] at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1430)
[junit] at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:280)
[junit] at org.hibernate.engine.PersistenceContext.initializeNonLazyCollections(PersistenceContext.java:796)
[junit] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
[junit] at org.hibernate.loader.Loader.loadEntity(Loader.java:1345)
[junit] at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:116)
[junit] at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:101)
[junit] at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:351)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:332)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:113)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:167)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:79)
[junit] at org.hibernate.impl.SessionImpl.get(SessionImpl.java:621)
[junit] at org.hibernate.impl.SessionImpl.get(SessionImpl.java:614)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:441)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:356)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:435)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:430)
[junit] at com.testing.dao.hibernate.UserDAOHibernate.getUser(UserDAOHibernate.java:30)
[junit] at com.testing.dao.UserDAOTest.testGetUser(UserDAOTest.java:45)
[junit] Caused by: net.sf.cglib.beans.BulkBeanException
[junit] at com.testing.model.ProjectRole$$BulkBeanByCGLIB$$e6c60362.setPropertyValues(<generated>)
[junit] at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:200)
[junit] ... 46 more
[junit] Caused by: java.lang.ClassCastException
[junit] ... 48 more
[junit] Testcase: testUpdateUser(com.testing.dao.UserDAOTest): Caused an ERROR
[junit] exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.testing.model.ProjectRole.setProject; nested exception is org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.testing.model.ProjectRole.setProject
[junit] org.springframework.orm.hibernate3.HibernateSystemException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.testing.model.ProjectRole.setProject; nested exception is org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.testing.model.ProjectRole.setProject
[junit] org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.testing.model.ProjectRole.setProject
[junit] at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:203)
[junit] at org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:173)
[junit] at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2919)
[junit] at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
[junit] at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:530)
[junit] at org.hibernate.loader.Loader.doQuery(Loader.java:436)
[junit] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
[junit] at org.hibernate.loader.Loader.loadCollection(Loader.java:1434)
[junit] at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:111)
[junit] at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488)
[junit] at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
[junit] at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1430)
[junit] at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:280)
[junit] at org.hibernate.engine.PersistenceContext.initializeNonLazyCollections(PersistenceContext.java:796)
[junit] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
[junit] at org.hibernate.loader.Loader.loadEntity(Loader.java:1345)
[junit] at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:116)
[junit] at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:101)
[junit] at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:351)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:332)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:113)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:167)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:79)
[junit] at org.hibernate.impl.SessionImpl.get(SessionImpl.java:621)
[junit] at org.hibernate.impl.SessionImpl.get(SessionImpl.java:614)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:441)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:356)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:435)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:430)
[junit] at com.testing.dao.hibernate.UserDAOHibernate.getUser(UserDAOHibernate.java:30)
[junit] at com.testing.dao.UserDAOTest.testUpdateUser(UserDAOTest.java:51)
[junit] Caused by: net.sf.cglib.beans.BulkBeanException
[junit] at com.testing.model.ProjectRole$$BulkBeanByCGLIB$$e6c60362.setPropertyValues(<generated>)
[junit] at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:200)
[junit] ... 46 more
[junit] Caused by: java.lang.ClassCastException
[junit] ... 48 more
[junit] Testcase: testAddUserRole(com.testing.dao.UserDAOTest): Caused an ERROR
[junit] exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.testing.model.ProjectRole.setProject; nested exception is org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.testing.model.ProjectRole.setProject
[junit] org.springframework.orm.hibernate3.HibernateSystemException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.testing.model.ProjectRole.setProject; nested exception is org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.testing.model.ProjectRole.setProject
[junit] org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.testing.model.ProjectRole.setProject
[junit] at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:203)
[junit] at org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:173)
[junit] at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2919)
[junit] at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
[junit] at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:530)
[junit] at org.hibernate.loader.Loader.doQuery(Loader.java:436)
[junit] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
[junit] at org.hibernate.loader.Loader.loadCollection(Loader.java:1434)
[junit] at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:111)
[junit] at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488)
[junit] at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
[junit] at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1430)
[junit] at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:280)
[junit] at org.hibernate.engine.PersistenceContext.initializeNonLazyCollections(PersistenceContext.java:796)
[junit] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
[junit] at org.hibernate.loader.Loader.loadEntity(Loader.java:1345)
[junit] at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:116)
[junit] at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:101)
[junit] at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:351)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:332)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:113)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:167)
[junit] at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:79)
[junit] at org.hibernate.impl.SessionImpl.get(SessionImpl.java:621)
[junit] at org.hibernate.impl.SessionImpl.get(SessionImpl.java:614)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:441)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:356)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:435)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:430)
[junit] at com.testing.dao.hibernate.UserDAOHibernate.getUser(UserDAOHibernate.java:30)
[junit] at com.testing.dao.UserDAOTest.testAddUserRole(UserDAOTest.java:77)
[junit] Caused by: net.sf.cglib.beans.BulkBeanException
[junit] at com.testing.model.ProjectRole$$BulkBeanByCGLIB$$e6c60362.setPropertyValues(<generated>)
[junit] at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:200)
[junit] ... 46 more
[junit] Caused by: java.lang.ClassCastException
[junit] ... 48 more
[junit] TEST com.testing.dao.UserDAOTest FAILED
[junit] Tests FAILED

----------------------------------------------------------------------

Should I change the projectrole mapping in the User object to a composite-element ? Any advice is appreciated.

Thanks for your time.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 3:45 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
It is a mapping mistake

Code:
/**
* @hibernate.property column="project_id" type="integer" not-null="true"
*
* @return project
*/


It maps project property as integer, see "many-to-one" and "one-to-many" mapping documentation.


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