-->
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.  [ 4 posts ] 
Author Message
 Post subject: Updated: now DataException:could not initialize a collection
PostPosted: Wed Aug 13, 2008 1:34 pm 
Newbie

Joined: Mon Jan 28, 2008 1:50 pm
Posts: 9
Location: EMC
Hi all,

I upgraded my jars:
hibernate 3.2 to hibernate 3.2.6
entitymanager 3.3.1 to entity manager 3.3.2

I am running with a Derby back end.

Everything was running perfectly in the previous version. Now I get the following exception:

javax.persistence.PersistenceException: org.hibernate.exception.DataException: could not initialize a collection: [com.emc.imf.core.model.Privilege.roles#component[componentuid,privilegekey]{componentuid=5, privilegekey=PrivilegeKey4}]
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:637)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:74)
at com.emc.imf.core.model.DbObjRetriever.getVAApps(DbObjRetriever.java:34)
at com.emc.imf.core.model.BOMFacadeManager.getVAApps(BOMFacadeManager.java:463)
at com.emc.imf.core.model.TestBOMComponents.getVAApps(TestBOMComponents.java:65)
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.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
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 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.exception.DataException: could not initialize a collection: [com.emc.imf.core.model.Privilege.roles#component[componentuid,privilegekey]{componentuid=5, privilegekey=PrivilegeKey4}]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:77)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2001)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:63)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:454)
at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:844)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:241)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:65)
... 25 more
Caused by: SQL Exception: Invalid character string format for type INTEGER.
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedResultSet.noStateChangeException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.setString(Unknown Source)
at org.hibernate.type.StringType.set(StringType.java:26)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:116)
at org.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:284)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1707)
at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1678)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1563)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1994)
... 41 more

It appears to populate the database with the persist correctly, but when I run a simple query:

EntityManager em = emf.createEntityManager();
em.createQuery("from VAApp").getResultList();

The VAApp object contains the Privilege object referenced above. Loading here is eager, not lazy.

HELP!!!!

Shannon

_________________
Shannon Moyes Clark


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 13, 2008 1:42 pm 
Beginner
Beginner

Joined: Fri Aug 05, 2005 3:36 am
Posts: 28
The "Caused by: SQL Exception: Invalid character string format for type INTEGER" is interesting. Do you want to post your code and mappings?

-larry


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 13, 2008 1:54 pm 
Newbie

Joined: Mon Jan 28, 2008 1:50 pm
Posts: 9
Location: EMC
I realize that it is saying that there is an string format for type integer. As I said, everything ran fine under the older version. Here are the relevant bits, I think:

The ddl:

CREATE TABLE APP.ROLE_PRIVILEGE (
COMPONENTUID INTEGER NOT NULL,
PRIVILEGEKEY VARCHAR(50) NOT NULL,
ROLEID INTEGER NOT NULL,
PRIMARY KEY (COMPONENTUID, PRIVILEGEKEY, ROLEID)
);

CREATE TABLE APP.ROLES (
ROLEID INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1 ,INCREMENT BY 1),
roleinheritancetype VARCHAR(20) NOT NULL,
COMPONENTID INTEGER NOT NULL);

CREATE TABLE APP.PRIVILEGES (
COMPONENTUID INTEGER NOT NULL,
DESCRIPTION VARCHAR(250),
PRIVILEGEKEY VARCHAR(50) NOT NULL,
PRIMARY KEY (COMPONENTUID, PRIVILEGEKEY)
);

CREATE TABLE APP.IMFCOMPONENT (
COMPONENTID INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1 ,INCREMENT BY 1),
COMPONENTTYPE VARCHAR(10) NOT NULL,
NAME VARCHAR(50) NOT NULL);

The class annotations:

Privilege class:

@Entity
@Table(name="PRIVILEGES")
public class Privilege implements Serializable{
@EmbeddedId
private Privilege.PK pk;

private String description;

@ManyToOne(fetch=FetchType.EAGER,
cascade = CascadeType.REFRESH)
@JoinColumn(name="COMPONENTUID", insertable=false)
private Component component;

@ManyToMany(fetch=FetchType.EAGER,
cascade= CascadeType.ALL
)
@JoinTable(
name="ROLE_PRIVILEGE",
joinColumns={@JoinColumn(name="PRIVILEGEKEY"),
@JoinColumn(name="COMPONENTUID")},
inverseJoinColumns={@JoinColumn(name="ROLEID")}

)
private Set<Role> roles;

@Embeddable
public static class PK implements Serializable {
private String privilegekey;
private long componentuid;
private static final long serialVersionUID = 1L;

public PK() {
super();
}
}
}

Role class:

@Entity
@Table(name="ROLES")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
name="roleinheritancetype",
discriminatorType=DiscriminatorType.STRING
)
@DiscriminatorValue("BASEROLE")

class Role implements Serializable{

@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
private long roleid;

@Enumerated(EnumType.STRING)
@Column(name="ROLETYPE")
private RoleType type;

@Version
@Column(name = "OBJ_VERSION")
private int obj_version;

@ManyToOne(targetEntity=VAApp.class,
fetch=FetchType.EAGER,
cascade = { CascadeType.REFRESH
}
)
@JoinColumn(name="COMPONENTID")
private Component componentid;

@ManyToMany(
targetEntity=com.emc.imf.core.model.Privilege.class,
fetch=FetchType.EAGER ,
cascade={CascadeType.REFRESH}
)
@JoinTable(
name="ROLE_PRIVILEGE", inverseJoinColumns={@JoinColumn(name="PRIVILEGEKEY"),
@JoinColumn(name="COMPONENTUID")},
joinColumns={@JoinColumn(name="ROLEID")}


)
private Set<Privilege> privileges;
...
}

Does this help?

Shannon

_________________
Shannon Moyes Clark


Top
 Profile  
 
 Post subject: More info, please help!
PostPosted: Wed Aug 13, 2008 5:33 pm 
Newbie

Joined: Mon Jan 28, 2008 1:50 pm
Posts: 9
Location: EMC
So I think I may know what is happening, and was wondering if someone could help me understand why.

I am using an intersection table called Role_Privilege to map a many to many relationship.

The first object (Privilege) contains a compound key, which is a string and an integer. The second object (Role) contains a auto generated integer key. The intersection table contains all three values, the compound key from the first object, and the integer key from the second.

Then I have the following join statement in the Privilege object:

@ManyToMany(fetch=FetchType.EAGER,
cascade= CascadeType.ALL
)
@JoinTable(
name="ROLE_PRIVILEGE",
joinColumns={@JoinColumn(name="PRIVILEGEKEY"),

@JoinColumn(name="COMPONENTUID")},
inverseJoinColumns={@JoinColumn(name="ROLEID")}

)
private Set<Role> roles;

The compound key is defined as:

public static class PK implements Serializable {
private String privilegekey;
private long componentuid;
public PK() {
super();
}
}


I should be able to use strings for join columns. When I first create the object that contains the compound key, I am setting it in the constructor. Is there something new that I need to do when I populate the object after a query, because I am doing an eager fetch?

Other suggestions would be greatly appreciated!

Shannon

_________________
Shannon Moyes Clark


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