giri wrote:
Hi List,
I am a newbie to hibernate, I have downloaded the hibernate and I could get the sample app running from my java application (my java application connects to the hsqldb).
Basically I am having trouble in connecting my sybase db using hibernate.
When I tried to connect sybase from my java demo object via hibernate I am getting the following error
-------
net.sf.hibernate.PropertyNotFoundException: Could not find a setter for property
session_id in class adbtest.ShoppingCart
----------
hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.sybase.jdbc2.jdbc.SybDriver</property>
<property name="hibernate.connection.url">jdbc:sybase:Tds:myURL.com:3029</property>
<property name="hibernate.connection.username">userN</property>
<property name="hibernate.connection.password">admin</property>
<property name="dialect">net.sf.hibernate.dialect.SybaseDialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">
net.sf.hibernate.transaction.JDBCTransactionFactory
</property>
<property name="hibernate.cache.provider_class">
net.sf.hibernate.cache.HashtableCacheProvider
</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="adbtest/Facility.hbm.xml"/>
</session-factory>
</hibernate-configuration>
----------------------------
I am using the same db url, username & password to connect the sybase using JDBC and it works OK (this means the connection properties are good)
Facility.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="adbtest.ShoppingCart" table="sh_dev.shopping_cart">
<id name="session_id" column="session_id" >
<generator class="increment"/>
</id>
<property name="site" column = "site" update="false" insert="false"/>
</class>
</hibernate-mapping>.
In my java object:
package adbtest;
import java.util.Date;
public class ShoppingCart {
private String site;
private int session_id;
public int getSessionID() {
return session_id;
}
private void setSessionID(int session_id) {
this.session_id = session_id;
}
public String getSite() {
return site;
}
public void setSite(String site) {
this.site = site;
}
}
package adbtest;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.cfg.Configuration;
import java.text.DateFormat;
import java.util.Date;
import java.util.List;
public class FacilityManager {
private SessionFactory sessionFactory;
public FacilityManager() {
try {
System.out.println("Initializing Hibernate");
sessionFactory = new Configuration().configure().buildSessionFactory();
System.out.println("Finished Initializing Hibernate");
} catch (HibernateException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws java.text.ParseException {
FacilityManager instance = new FacilityManager();
List events = instance.listEvents();
for (int i = 0; i<events.size(); i++) {
ShoppingCart theEvent = (ShoppingCart) events.get(i);
System.out.println("*********sessionid " + theEvent.getSessionID() + " Site: " + theEvent.getSite());
}
System.exit(0);
}
private List listEvents() {
try {
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
List result = session.find("from sh_dev.shopping_cart");
tx.commit();
session.close();
return result;
} catch (HibernateException e) {
throw new RuntimeException(e.getMessage());
}
}
}
Here is the complete error message I am getting:
Initializing Hibernate
INFO - Hibernate 2.1.7
INFO - hibernate.properties not found
INFO - using CGLIB reflection optimizer
INFO - using JDK 1.4 java.sql.Timestamp handling
INFO - configuring from resource: /hibernate.cfg.xml
INFO - Configuration resource: /hibernate.cfg.xml
INFO - Mapping resource: adbtest/Facility.hbm.xml
INFO - Mapping class: adbtest.ShoppingCart -> ql_dev.shopping_cart
INFO - Configured SessionFactory: null
INFO - processing one-to-many association mappings
INFO - processing one-to-one association property references
INFO - processing foreign key constraints
INFO - Using dialect: net.sf.hibernate.dialect.SybaseDialect
INFO - Use outer join fetching: true
INFO - Using Hibernate built-in connection pool (not for production use!)
INFO - Hibernate connection pool size: 20
INFO - using driver: com.sybase.jdbc2.jdbc.SybDriver at URL: jdbc:sybase:Tds:myURL.com:3029
INFO - connection properties: {user=userN, password=admin}
INFO - Transaction strategy: net.sf.hibernate.transaction.JDBCTransactionFactor
y
INFO - No TransactionManagerLookup configured (in JTA environment, use of proce
ss level read-write cache is not recommended)
INFO - Use scrollable result sets: true
INFO - Use JDBC3 getGeneratedKeys(): false
INFO - Optimize cache for minimal puts: false
INFO - echoing all SQL to stdout
INFO - Query language substitutions: {}
INFO - cache provider: net.sf.hibernate.cache.HashtableCacheProvider
INFO - instantiating and configuring caches
INFO - building session factory
net.sf.hibernate.PropertyNotFoundException: Could not find a setter for property
session_id in class adbtest.ShoppingCart
at net.sf.hibernate.property.BasicPropertyAccessor.getSetter(BasicProper
tyAccessor.java:131)
at net.sf.hibernate.mapping.Property.getSetter(Property.java:178)
at net.sf.hibernate.persister.AbstractEntityPersister.<init>(AbstractEnt
ityPersister.java:591)
at net.sf.hibernate.persister.EntityPersister.<init>(EntityPersister.jav
a:692)
at net.sf.hibernate.persister.PersisterFactory.createClassPersister(Pers
isterFactory.java:42)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.ja
va:137)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.
java:796)
at adbtest.FacilityManager.<init>(FacilityManager.java:21)
at adbtest.FacilityManager.main(FacilityManager.java:29)
Exception in thread "main" java.lang.NullPointerException
at adbtest.FacilityManager.listEvents(FacilityManager.java:56)
at adbtest.FacilityManager.main(FacilityManager.java:45)
Any help would be highly appreciated.
Thanks in advance.