Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type In directory sc8-pr-cvs1:/tmp/cvs-serv6974/type Modified Files: AbstractType.java EntityType.java ManyToOneType.java ObjectType.java Type.java Log Message: fixed a problem in ObjectType fixed a bug where PreparedStatements were returned to cache with setMaxRows() still set Index: AbstractType.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type/AbstractType.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** AbstractType.java 9 Feb 2003 07:41:16 -0000 1.6 --- AbstractType.java 19 Feb 2003 02:02:07 -0000 1.7 *************** *** 60,74 **** SessionImplementor session, Object owner) ! throws HibernateException, SQLException { ! return nullSafeGet(rs, names, session, owner); ! } ! public Object resolveIdentifier(Object value, SessionImplementor session, Object owner) ! throws HibernateException, SQLException { ! return value; ! } } --- 60,79 ---- SessionImplementor session, Object owner) ! throws HibernateException, SQLException { ! return nullSafeGet(rs, names, session, owner); ! } ! public Object resolveIdentifier(Object value, SessionImplementor session, Object owner) ! throws HibernateException, SQLException { ! return value; ! } + + public boolean isObjectType() { + return false; } + + } Index: EntityType.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type/EntityType.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** EntityType.java 9 Feb 2003 07:41:16 -0000 1.6 --- EntityType.java 19 Feb 2003 02:02:07 -0000 1.7 *************** *** 51,74 **** } ! protected Serializable getIdentifier(Object value, SessionImplementor session) throws HibernateException { ! if (value == null) { ! return null; ! } ! else { ! Serializable id = session.getEntityIdentifier(value); ! if (id==null) { ! try { ! // we only allow this case to support Session.update() ! id = session.getFactory().getPersister(persistentClass).getIdentifier(value); ! } ! catch (HibernateException he) { ! // transient instance with no identifier property ! } ! if (id==null) throw new HibernateException( ! "object references a transient instance - save the transient instance first" ! ); ! } ! return id; ! } } --- 51,56 ---- } ! protected final Serializable getIdentifier(Object value, SessionImplementor session) throws HibernateException { ! return session.getEntityIdentifierIfNotUnsaved(value); } Index: ManyToOneType.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type/ManyToOneType.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ManyToOneType.java 9 Feb 2003 07:41:16 -0000 1.4 --- ManyToOneType.java 19 Feb 2003 02:02:07 -0000 1.5 *************** *** 48,69 **** SessionImplementor session, Object owner) ! throws HibernateException, SQLException { ! return (Serializable) session.getFactory().getIdentifierType( getPersistentClass() ) ! .nullSafeGet(rs, names, session, owner); ! } ! public Object resolveIdentifier(Object value, SessionImplementor session, Object owner) ! throws HibernateException, SQLException { ! ! if (value==null) { ! return null; ! } ! else { ! return session.internalLoad( getPersistentClass(), (Serializable) value ); ! } ! } } --- 48,68 ---- SessionImplementor session, Object owner) ! throws HibernateException, SQLException { ! return (Serializable) session.getFactory().getIdentifierType( getPersistentClass() ).nullSafeGet(rs, names, session, owner); ! } ! public Object resolveIdentifier(Object value, SessionImplementor session, Object owner) ! throws HibernateException, SQLException { + if (value==null) { + return null; + } + else { + return session.internalLoad( getPersistentClass(), (Serializable) value ); + } } + + } Index: ObjectType.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type/ObjectType.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ObjectType.java 19 Jan 2003 11:47:08 -0000 1.4 --- ObjectType.java 19 Feb 2003 02:02:08 -0000 1.5 *************** *** 77,80 **** --- 77,82 ---- throws HibernateException, SQLException { + //if ( names.length!=2 ) throw new HibernateException("object type mapping must specify exactly two columns"); + String className = (String) Hibernate.STRING.nullSafeGet( rs, names[0] ); Serializable id = (Serializable) Hibernate.SERIALIZABLE.nullSafeGet( rs, names[1] ); *************** *** 103,108 **** } else { String className = value.getClass().getName(); - Serializable id = session.getEntityIdentifier(value); Hibernate.STRING.nullSafeSet(st, className, index, session); Hibernate.SERIALIZABLE.nullSafeSet(st, id, index+1, session); --- 105,110 ---- } else { + Serializable id = session.getEntityIdentifierIfNotUnsaved(value); String className = value.getClass().getName(); Hibernate.STRING.nullSafeSet(st, className, index, session); Hibernate.SERIALIZABLE.nullSafeSet(st, id, index+1, session); *************** *** 149,166 **** SessionImplementor session, Object owner) ! throws HibernateException, SQLException { ! ObjectTypeCacheEntry e = (ObjectTypeCacheEntry) cached; ! return (cached==null) ? null : session.load(e.clazz, e.id); ! } ! /** ! * @see net.sf.hibernate.type.Type#disassemble(Object, SessionImplementor) ! */ ! public Serializable disassemble(Object value, SessionImplementor session) ! throws HibernateException { ! return (value==null) ? null : new ObjectTypeCacheEntry( value.getClass(), session.getEntityIdentifier(value) ); ! } } --- 151,176 ---- SessionImplementor session, Object owner) ! throws HibernateException, SQLException { ! ObjectTypeCacheEntry e = (ObjectTypeCacheEntry) cached; ! return (cached==null) ? null : session.load(e.clazz, e.id); ! } + /** + * @see net.sf.hibernate.type.Type#disassemble(Object, SessionImplementor) + */ + public Serializable disassemble(Object value, SessionImplementor session) + throws HibernateException { + return (value==null) ? null : new ObjectTypeCacheEntry( value.getClass(), session.getEntityIdentifier(value) ); } + + /** + * @see net.sf.hibernate.type.Type#isObjectType() + */ + public boolean isObjectType() { + return true; + } + + } Index: Type.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type/Type.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Type.java 9 Feb 2003 07:41:16 -0000 1.7 --- Type.java 19 Feb 2003 02:02:09 -0000 1.8 *************** *** 52,55 **** --- 52,65 ---- /** + * Is this an "object" type, ie. a reference to a persistent entity + * that is not modelled as a (foreign key) association. + * + * @param mapping + * @return int[] + * @throws MappingException + */ + public boolean isObjectType(); + + /** * Return the SQL type codes for the columns mapped by this type. The codes * are defined on <tt>java.sql.Types</tt>. |