Hibernate version:
2.1.6
Mapping documents:
NA
Code between sessionFactory.openSession() and session.close():
NA
Full stack trace of any exception that occurs:
No Exception this is a design question
Name and version of the database you are using:
MySQL
The generated SQL (show_sql=true):
NA
Debug level Hibernate log excerpt:
16:27:36,134 INFO Environment:469 - Hibernate 2.1.6
16:27:36,154 INFO Environment:503 - loaded properties from resource hibernate.properties: {hibernate.connection.username=root, hibernate.connection.password=, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.connection.url=jdbc:mysql://localhost:3306/services, hibernate.connection.driver_class=com.mysql.jdbc.Driver}
16:27:36,154 INFO Environment:529 - using CGLIB reflection optimizer
16:27:36,164 INFO Configuration:350 - Mapping resource: com/pojo/Quote.hbm.xml
16:27:36,725 INFO Binder:229 - Mapping class: com.pojo.Quote -> quotes
16:27:36,835 INFO Configuration:350 - Mapping resource: com/pojo/Symbol.hbm.xml
16:27:36,875 INFO Binder:229 - Mapping class: com.pojo.Symbol -> symbols
16:27:36,885 INFO Configuration:627 - processing one-to-many association mappings
16:27:36,885 INFO Binder:1181 - Mapping collection: com.pojo.Symbol.quotes -> quotes
16:27:36,895 INFO Configuration:636 - processing one-to-one association property references
16:27:36,895 INFO Configuration:661 - processing foreign key constraints
16:27:36,915 INFO Dialect:82 - Using dialect: net.sf.hibernate.dialect.MySQLDialect
16:27:36,925 INFO SettingsFactory:59 - Maximim outer join fetch depth: 2
16:27:36,925 INFO SettingsFactory:63 - Use outer join fetching: true
16:27:36,925 INFO DriverManagerConnectionProvider:42 - Using Hibernate built-in connection pool (not for production use!)
16:27:36,925 INFO DriverManagerConnectionProvider:43 - Hibernate connection pool size: 20
16:27:36,975 INFO DriverManagerConnectionProvider:77 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/services
16:27:36,975 INFO DriverManagerConnectionProvider:78 - connection properties: {user=root, password=}
16:27:36,985 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
16:27:37,196 INFO SettingsFactory:103 - Use scrollable result sets: true
16:27:37,196 INFO SettingsFactory:106 - Use JDBC3 getGeneratedKeys(): true
16:27:37,196 INFO SettingsFactory:109 - Optimize cache for minimal puts: false
16:27:37,206 INFO SettingsFactory:118 - Query language substitutions: {}
16:27:37,206 INFO SettingsFactory:129 - cache provider: net.sf.hibernate.cache.EhCacheProvider
16:27:37,206 INFO Configuration:1116 - instantiating and configuring caches
16:27:37,346 INFO SessionFactoryImpl:118 - building session factory
16:27:37,536 INFO ReflectHelper:186 - reflection optimizer disabled for: com.pojo.Symbol, IllegalArgumentException: Cannot find matching method/constructor 16:27:37,576 INFO ReflectHelper:186 - reflection optimizer disabled for: com.pojo.Quote, IllegalArgumentException: Cannot find matching method/constructor 16:27:37,736 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
16:27:37,796 INFO SessionFactoryImpl:534 - closing
16:27:37,796 INFO DriverManagerConnectionProvider:143 - cleaning up connection pool: jdbc:mysql://localhost:3306/services
Look at the bold part the excerpt. I know why this happens but just want to make sure what I know is correct :). The pojo Hiberante makes is an abstract class (cool feature). so we have ...
public abstract class AbstractPojo
{
public constructor1() {}
public constructor2(param1) {}
public constructor3(param1, param2) {}
}
I created a concrete class that extends AbstractPojo so we now have ...
public class ConcretePojo extends AbstractPojo
{
public constructor1() {}
public constructor2(param1) {}
public constructor3(param1, param2) {}
}
Now, this will not produce the the two bold lines in the excerpt. In fact this runs straight through with no additional debug information other then the norm. To get the bold lines to appear as in the above excerpt ... do the following ...
public abstract class ConcretePojo extends AbstractPojo
{
protected constructor1() {}
protected constructor2(param1) {}
public constructor3(param1, param2) {}
}
The 2 protected constructors cause the "optimizer ... disable" messages to appear. I made them protected so that constructor3 would be the only option to the developer. This forces the pojo to be instantiated in a valid state as constructor3 contains validation code for the parameters. My question is ... what do loose by Hibernate not being able to "optimize the class"?
|