[Hibernate-JIRA] Created: (HHH-2382) DefaultLoadEventListener#onLoad throws exception when DelayedPostInsertIdentifier is set as an entity id
by Eelco Hillenius (JIRA)
DefaultLoadEventListener#onLoad throws exception when DelayedPostInsertIdentifier is set as an entity id
--------------------------------------------------------------------------------------------------------
Key: HHH-2382
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2382
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.2.1, 3.2.2, 3.2.0.ga
Reporter: Eelco Hillenius
DefaultLoadEventListener#onLoad has this code:
if ( idClass != null && ! idClass.isInstance( event.getEntityId() ) ) {
throw new TypeMismatchException(
"Provided id of the wrong type. Expected: " + idClass + ", got " + event.getEntityId().getClass());
}
However, EntityIdentityInsertAction has this in it's constructor:
delayedEntityKey = isDelayed ? generateDelayedEntityKey() : null;
and method:
private synchronized EntityKey generateDelayedEntityKey() {
if ( !isDelayed ) {
throw new AssertionFailure( "cannot request delayed entity-key for non-delayed post-insert-id generation" );
}
return new EntityKey( new DelayedPostInsertIdentifier(), getPersister(), getSession().getEntityMode() );
}
In case an insert is tried outside of an existing transaction users may run into this problem (like I did).
I don't know what the best fix is. The easiest fix would be:
Index: /Users/eelcohillenius/Documents/workspace/hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java
===================================================================
--- /Users/eelcohillenius/Documents/workspace/hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java (revision 11098)
+++ /Users/eelcohillenius/Documents/workspace/hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java (working copy)
@@ -5,6 +5,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.NonUniqueObjectException;
@@ -10,7 +11,7 @@
import org.hibernate.NonUniqueObjectException;
import org.hibernate.PersistentObjectException;
import org.hibernate.TypeMismatchException;
-import org.hibernate.EntityMode;
+import org.hibernate.action.DelayedPostInsertIdentifier;
import org.hibernate.cache.CacheConcurrencyStrategy;
import org.hibernate.cache.CacheKey;
import org.hibernate.cache.entry.CacheEntry;
@@ -82,7 +83,7 @@
}
else {
Class idClass = persister.getIdentifierType().getReturnedClass();
- if ( idClass != null && ! idClass.isInstance( event.getEntityId() ) ) {
+ if ( idClass != null && ! (idClass.isInstance( event.getEntityId() ) || event.getEntityId() instanceof DelayedPostInsertIdentifier )) {
throw new TypeMismatchException(
"Provided id of the wrong type. Expected: " + idClass + ", got " + event.getEntityId().getClass()
);
but that would look like a quick hack to me.
--
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
16 years
[Hibernate-JIRA] Commented: (HHH-468) MysqlDialect incorrectly maps java.lang.Boolean to SQL BIT
by Laurent Mallet (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-468?page=co... ]
Laurent Mallet commented on HHH-468:
------------------------------------
Hi gavin,
My team is working with Seam and jboss 4.2 and discover this bug when we install our application on the pre-production plateform
on our entities objects.
Our pre-production and production plateforms are in RHEL 5. Our developpement plateform is on RHEL 4.
The main difference is also the MySQL version.
This bug is really annonying because :
- RHEL 5 install version 5 of MySQL (No support on MySQL 4)
- MySQL 4 is at end of his lifecycle
- in JPA, it's so ugly to change our code from boolean to int
- a search in google "MySQL 5 boolean BIT problem" shows so many desesperate people
- credibility of jboss : this bug is so annoying that my team doesn't understand that it could be possible; they are afraid that it could have
other ugly bugs..
Laurent Mallet
CTO of Oxalya
> MysqlDialect incorrectly maps java.lang.Boolean to SQL BIT
> ----------------------------------------------------------
>
> Key: HHH-468
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-468
> Project: Hibernate3
> Issue Type: Bug
> Affects Versions: 3.0.3
> Environment: Hibernate 3.0, MySQL.
> Reporter: Mark Matthews
> Assignee: Scott Marlow
>
> I didn't track down how java.lang.Boolean gets mapped to Types.BIT in hibernate, but you probably _don't_ want to map to "bit" like you do in MysqlDialect.
> "bit", according to SQL99 (it's not in the core standard, and the type was actually dropped for sql2k3) is a bitfield, not a boolean value. You can of course define a bit(1), but it is technically more correct for java.lang.Boolean to map to a SQL BOOLEAN for MySQL since we support a BOOLEAN and a BIT.
> It looks like the JDBC-3.0 guys ignored what the standard said, because in reality you'd want BIT to map to something like byte[], or java.util.BitSet if you were tracking how the SQL standard defines BIT.
> I'm guessing you probably want to map to "boolean", which the JDBC driver will automagically convert for you, as it silently maps to TINYINT(1) on the server side.
--
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
16 years
[Hibernate-JIRA] Commented: (HHH-1088) IdentifierProjection does not work with composite keys
by Paul Benedict (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1088?page=c... ]
Paul Benedict commented on HHH-1088:
------------------------------------
An awesome patch. I need this for my enterprise. Our DA group uses composite keys heavily for associative entities.
> IdentifierProjection does not work with composite keys
> ------------------------------------------------------
>
> Key: HHH-1088
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1088
> Project: Hibernate3
> Issue Type: Bug
> Components: query-criteria
> Affects Versions: 3.1 rc2
> Reporter: Max Muermann
> Attachments: CompositeIdProjection.java, CriteriaLoader.java
>
>
> When working with Criteria queries, the IdentifierProjection breaks if the entity has a composite key.
> In IdentifierProjection.java:
> public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery)
> throws HibernateException {
> StringBuffer buf = new StringBuffer();
> String[] cols = criteriaQuery.getIdentifierColumns(criteria);
> for ( int i=0; i<cols.length; i++ ) {
> buf.append( cols[i] )
> .append(" as y")
> .append(position + i)
> .append('_');
> }
> return buf.toString();
> }
> This method does not add commas as separators between the column names. Easily fixed by adding
> if (i<col.length-1)
> buf.append(",");
> as the last statement inside the loop.
> However, this leads to another problem:
> the type returned by IdentifierProjection.geType is the (single) type of the composite id component. The query will however return the property values of the id component without a mapping step.
--
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
16 years