I am using Hibernate 2.1.2.
The mapping is question is the following:
Code:
<hibernate-mapping>
<class name="com.foo.bar.beans.user.User" table="USERS" proxy="com.foo.bar.beans.user.User" dynamic-update="false" dynamic-insert="false" mutable="true">
<id name="userId" column="USERID" type="java.lang.Long" unsaved-value="null">
<generator class="sequence">
<param name="sequence">SEQ_USERID</param>
</generator>
</id>
<property name="firstName" type="java.lang.String" update="true" insert="true" column="FIRSTNAME" not-null="true"/>
...
...
</class>
</hibernate-mapping>
This is a sample section of code
Code:
Long userId = new Long(1);
UserDAO userDAO = new UserDAO();
User user = userDAO.searchByPrimaryKey(userId);
logger.debug("Class: " + user.getClass());
if (user.getClass().isInstance(new User()))
{
logger.debug("Result is an instance of the User object.");
}
else
{
logger.debug("Result is NOT an instance of the User object.");
}
The following is the output
Code:
Class: com.foo.bar.beans.user.User$$EnhancerByCGLIB$$f0dddb0d
Result is NOT an instance of the User object.
I am guessing that this is a result of Proxy setting. Does anyone know how I can get the result to be an instance of my User object. I have tried to typecast it but it makes no difference.
Any suggestions?