Issue
Recently I updated my hibernate from 3.1 to 4.3 and I am trying to use annotations instead of xml.With Xml everything is working fine and annotation throw up a bunch of exceptions. And the final one I am stuck with is the below stack trace please shed some light on it. I terribly need a help because the stack trace is not giving me any specific area to work on.
I am using:
Hibernate 4.3
javaassist 3.18
I tried to use javaassist jar which everyone suggested but that didn't help me. However I have my doubts, buildSessionFactory is deprecated for hibernate 4.5 and is this a culprit by any chance? Just including my HibernateUtils if it of any help
Properties connProperties = new Properties();
connProperties.setProperty( "hibernate.connection.datasource", "java:comp/env/" + MASTER_JDBC_RESOURCE_NAME );
configuration = new Configuration();
configuration.addProperties(connProperties);
sessionFactory = configuration.configure().buildSessionFactory();
Properties hibernateProperties = configuration.getProperties();
for (Object k : hibernateProperties.keySet()) {
System.out.println("Hibernate Key "+k.toString());
}
String testCon = hibernateProperties.getProperty("hibernate.test_connections");
testConnections = StringUtils.stringToBool(testCon);
My Stacktrace
org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.component.PojoComponentTuplizer] at org.hibernate.tuple.component.ComponentTuplizerFactory.constructTuplizer(ComponentTuplizerFactory.java:101) at org.hibernate.tuple.component.ComponentTuplizerFactory.constructDefaultTuplizer(ComponentTuplizerFactory.java:122) at org.hibernate.tuple.component.ComponentMetamodel.(ComponentMetamodel.java:81) at org.hibernate.mapping.Component.getType(Component.java:180) at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:322) at org.hibernate.mapping.RootClass.validate(RootClass.java:271) at org.hibernate.cfg.Configuration.validate(Configuration.java:1360) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1851) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930) at wadetech.DB.base.HibernateUtils.(HibernateUtils.java:111) at wadetech.DB.base.BaseDAO.(BaseDAO.java:43) at wadetech.DB.DAOS.__MaintenanceDAO.(__MaintenanceDAO.java:10) at com.at.project.utils.runtime.RuntimeModifier.HasExecuted(RuntimeModifier.java:127) at wadetech.listeners.ModificationScriptStartupListener.contextInitialized(ModificationScriptStartupListener.java:47) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5528) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at org.hibernate.tuple.component.ComponentTuplizerFactory.constructTuplizer(ComponentTuplizerFactory.java:98) ... 22 more Caused by: org.hibernate.PropertyNotFoundException: Could not find a setter for property bytes in class java.lang.String at org.hibernate.property.BasicPropertyAccessor.createSetter(BasicPropertyAccessor.java:246) at org.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:240) at org.hibernate.mapping.Property.getSetter(Property.java:328) at org.hibernate.tuple.component.PojoComponentTuplizer.buildSetter(PojoComponentTuplizer.java:159) at org.hibernate.tuple.component.AbstractComponentTuplizer.(AbstractComponentTuplizer.java:65) at org.hibernate.tuple.component.PojoComponentTuplizer.(PojoComponentTuplizer.java:59) ... 27 more
Thanks for any help
Solution
I googled for a solution and unfortunately most of the answers that solved for others dint help me.A couple of the most voted answers is mentioning below:
- Use of javaassist.jar and make sure when you use its compatible with your hibernate version. For hibernate 4.3.11 javaassist 3.18 is okay.
- Make sure you define matching getters/setters for all your properties.
My case was similar to case 2 so if anyone stuck with these errors and if case 1 dint help you, only thing you can do is a full check-up and comparison of your entity class with the table and column name. For me my task was to move the mapping from XML to annotation, and anyone facing issue due to this migration needs to cross-check their entity class with corresponding .hbm.xml files.
Answered By - Lilac
Answer Checked By - Willingham (JavaFixing Volunteer)