[Hibernate-JIRA] Created: (HHH-3273) One-to-Many relationship not working with custom Loader
by Darren Hicks (JIRA)
One-to-Many relationship not working with custom Loader
--------------------------------------------------------
Key: HHH-3273
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3273
Project: Hibernate3
Issue Type: Bug
Affects Versions: 3.2.6, 3.2.5, 3.2.4, 3.2.3, 3.2.2, 3.2.1
Environment: hibernate-3.2.6.jar
Reporter: Darren Hicks
Within the context of a One-to-Many relationship, NamedQueryCollectionInitializer .initialize() never actually populates the PersistantBag on the parent after it calls query.setCollectionKey( key ).setFlushMode( FlushMode.MANUAL ).list() to retrieve the children.
This is documented in the forums here: http://forums.hibernate.org/viewtopic.php?t=986428
Additionally, the poster has a fix posted which may solve the problem, or at least lay out the groundwork for a solution. Here is the proposed implementation of NamedQueryCollectionInitializer.initialize():
public void initialize(Serializable key, SessionImplementor session)
throws HibernateException {
if (log.isDebugEnabled()) {
log.debug("initializing collection: " + persister.getRole()
+ " using named query: " + queryName);
}
// TODO: is there a more elegant way than downcasting?
AbstractQueryImpl query = (AbstractQueryImpl) session
.getNamedSQLQuery(queryName);
if (query.getNamedParameters().length > 0) {
query.setParameter(query.getNamedParameters()[0], key, persister
.getKeyType());
} else {
query.setParameter(0, key, persister.getKeyType());
}
List list = query.setCollectionKey(key).setFlushMode(FlushMode.MANUAL)
.list();
// Uh, how 'bout we save the collection for later retrieval?
CollectionKey collectionKey = new CollectionKey(persister, key, session
.getEntityMode());
for (Object object : session.getPersistenceContext()
.getCollectionsByKey().keySet()) {
if (collectionKey.equals(object)) {
PersistentCollection persistentCollection = session
.getPersistenceContext().getCollection(collectionKey);
Serializable[] serializables = new Serializable[list.size()];
for (int i = 0; i < list.size(); i++) {
serializables[i] = persister.getElementType().disassemble(
list.get(i), session,
persistentCollection.getOwner());
}
persistentCollection.initializeFromCache(persister,
serializables, persistentCollection.getOwner());
persistentCollection.setSnapshot(key, persistentCollection
.getRole(), serializables);
persistentCollection.afterInitialize();
session.getPersistenceContext().getCollectionEntry(
persistentCollection).postInitialize(
persistentCollection);
}
}
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
13 years, 11 months
[Hibernate-JIRA] Created: (HHH-5825) Map<EnumType, String> doesn't work
by Mattias Avelin (JIRA)
Map<EnumType, String> doesn't work
----------------------------------
Key: HHH-5825
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5825
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.6.0
Environment: Ubuntu linux 10.10,
OpenJDK Runtime Environment (IcedTea6 1.9.2) (6b20-1.9.2-0ubuntu2),
OpenJDK Server VM (build 19.0-b09, mixed mode)
Mysql Connector 5.1.14
Reporter: Mattias Avelin
@ElementCollection
@MapKeyEnumerated(EnumType.STRING)
private Map<AltIdType, String> altIds = new HashMap<AltIdType, String>();
results in a error when trying to generate DB with hibernate.hbm2ddl.auto.
Stacktrace:
javax.persistence.PersistenceException: [PersistenceUnit: iwebPU] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
at se.ngm.iweb.persistence.DB.<init>(DB.java:20)
at se.ngm.iweb.persistence.DBTest.createDB(DBTest.java:44)
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Map, for columns: [org.hibernate.mapping.Column(altIds)]
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:859)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
When I test the same code using hibernate 3.5.1 it works!
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
13 years, 11 months
[Hibernate-JIRA] Created: (HHH-5822) Entities can't also be MappedSuperclasses
by Laran Evans (JIRA)
Entities can't also be MappedSuperclasses
-----------------------------------------
Key: HHH-5822
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5822
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.6.0.Beta1, 3.5.2
Reporter: Laran Evans
I recently upgraded Hibernate and discovered trouble.
We've got a situation where we have two classes mapped to a single table.
@MappedSuperclass
@Entity
@Table(name="thing")
class ThingLite {
// ... basic, shared fields
}
@Entity
@Table(name="thing")
class Thing extends ThingLite {
// ... extra fields
}
Both classes do truly map to the same table. ThingLite just doesn't pull back all of the fields that Thing does. The table contains a blob column which we don't need most of the time.
In retrospect, we could have used a joined table strategy, separating the blob column and the fields specific to Thing into a separate table. But we didn't. And going back now to redesign the tables isn't an option.
HHH-5125 makes it no longer possible to have a superclass that is both an Entity and a MappedSuperclass, and I'm not convinced that it shouldn't be allowed.
Do you guys agree that it should be possible? I can't think of a specific reason that it shouldn't be.
An alternative approach that I thought of would be to use a joined inheritance approach, joining on the same table to get the additional fields for Thing. When I tried it however I got errors relating to circular references. I don't quite understand why this should be the case. Niether Thing nor ThingLite have references to one another other than the fact that Thing extends ThingLite.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
13 years, 11 months
[Hibernate-JIRA] Created: (EJB-328) Missing flush before lock() when LockModeType is AUTO
by Per Olesen (JIRA)
Missing flush before lock() when LockModeType is AUTO
-----------------------------------------------------
Key: EJB-328
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-328
Project: Hibernate Entity Manager
Issue Type: Bug
Components: EntityManager
Affects Versions: 3.3.1.GA
Environment: core: 3.2.5.ga
entitymanager: 3.3.1.ga
annotations: 3.3.0.ga
Reporter: Per Olesen
Priority: Minor
When I try to WRITE lock() a newly persisted entity using entityManager.lock, I get a StaleObjectStateException, telling me that some other transaction updated or deleted the row. I am doing this in the same transaction (persist and lock).
By digging into the code, I see that the exception is thrown inside the SelectLockingStrategy.lock method, around these lines:
ResultSet rs = st.executeQuery();
try {
if ( !rs.next() ) {
if ( factory.getStatistics().isStatisticsEnabled() ) {
factory.getStatisticsImplementor()
.optimisticFailure( lockable.getEntityName() );
}
throw new StaleObjectStateException( lockable.getEntityName(), id );
}
}
The query executed here is the one which performs the select on id with FOR UPDATE. This select finds nothing, hence the exception.
Setting show_sql = true shows me, that no insert is performed. Debugging the flush mode tells me, that it is set to AUTO.
Shouldn't AUTO flush mode have the side effect, that a flush is performed before a query?
Performing an explicit flush, before the lock, makes everything green :-), so this is my current work-around.
Here is the exception (sanitized for company info):
org.springframework.orm.jpa.JpaOptimisticLockingFailureException: nested exception is javax.persistence.OptimisticLockException
Caused by: javax.persistence.OptimisticLockException
at org.hibernate.ejb.AbstractEntityManagerImpl.wrapStaleStateException(AbstractEntityManagerImpl.java:643)
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:600)
at org.hibernate.ejb.AbstractEntityManagerImpl.lock(AbstractEntityManagerImpl.java:379)
...
Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.foo.bar#32]
at org.hibernate.dialect.lock.SelectLockingStrategy.lock(SelectLockingStrategy.java:78)
at org.hibernate.persister.entity.AbstractEntityPersister.lock(AbstractEntityPersister.java:1334)
at org.hibernate.event.def.AbstractLockUpgradeEventListener.upgradeLock(AbstractLockUpgradeEventListener.java:88)
at org.hibernate.event.def.DefaultLockEventListener.onLock(DefaultLockEventListener.java:64)
at org.hibernate.impl.SessionImpl.fireLock(SessionImpl.java:584)
at org.hibernate.impl.SessionImpl.lock(SessionImpl.java:576)
at org.hibernate.ejb.AbstractEntityManagerImpl.lock(AbstractEntityManagerImpl.java:376)
...
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
13 years, 11 months
[Hibernate-JIRA] Created: (HHH-5819) HibernateException: org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions. This eception occurs randomly.Can someone help me out?
by Sankalp Shah (JIRA)
HibernateException: org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions. This eception occurs randomly.Can someone help me out?
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-5819
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5819
Project: Hibernate Core
Issue Type: Bug
Environment: Java,jsk1.5,oracle 10g
Reporter: Sankalp Shah
HibernateException:
org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at org.hibernate.collection.AbstractPersistentCollection.setCurrentSession(AbstractPersistentCollection.java:410)
at org.hibernate.event.def.OnUpdateVisitor.processCollection(OnUpdateVisitor.java:43)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:101)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:61)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:55)
at org.hibernate.event.def.AbstractVisitor.process(AbstractVisitor.java:123)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:293)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:223)
at org.hibernate.event.def.DefaultUpdateEventListener.performSaveOrUpdate(DefaultUpdateEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireUpdate(SessionImpl.java:564)
at org.hibernate.impl.SessionImpl.update(SessionImpl.java:552)
at org.hibernate.impl.SessionImpl.update(SessionImpl.java:544)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
13 years, 11 months