on 05-30-2006 12:46 PM
hi,
i want to use hibernate instead of entitybeans .i have some idea about hibernate that meas i can write simple java progarms for hibernate.But i do not know .how to implement hibernate with session Beans(<i><b>where to put hibernate.cfg.xml in ejb project</b></i>.in webproject i can place hibernate.cfg.xml <u><i>in webinf/classes in case of ejb project where can i place hibernate.cfg.xml</i></u>)
regards
<i><b>Guru</b></i>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi
i am getting exception like
org.hibernate.HibernateException: Could not find datasource
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:48)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:80)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:301)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:111)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1497)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1041)
at in.one.Guru.main(Guru.java:32)
<u><i><b>code:</b></i></u>
!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- properties -->
<property name="connection.datasource">jdbc/SAPJ2EDB</property>
<property name="dialect">org.hibernate.dialect.SAPDBDialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="transaction.manager_lookup_class">
org.hibernate.transaction.SAPWebASTransactionManagerLookup
</property>
<property name="current_session_context_class">thread</property>
<!--
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
-->
<!-- mapping files -->
<mapping resource="in/one/Emp.hbm.xml"/>
</session-factory>
</hibernate-configuration>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="in.one.Emp" table="Guru">
<!-- A 32 hex character is our surrogate key. It's automatically
generated by Hibernate with the UUID pattern. -->
<id name="empNo" type="string" unsaved-value="null" >
<column name="DEP_ID" sql-type="string" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="empName" column="NAME"/>
</class>
</hibernate-mapping>
<!-- parsed in 0ms -->
public class Emp {
String empNo;
String empName;
/**
* @return
*/
public String getEmpName() {
return empName;
}
/**
* @return
*/
public String getEmpNo() {
return empNo;
}
/**
* @param string
*/
public void setEmpName(String string) {
empName = string;
}
/**
* @param string
*/
public void setEmpNo(String string) {
empNo = string;
}
}
public class Guru {
public static void main(String[] args) {
Configuration cfg = new Configuration();
File f = new File("C:\goMobileSales\nagworkspace\HibernateProject\in\one\hibernate.cfg.xml");
System.out.println("File");
cfg.configure(f);
//cfg.addClass(in.one.Emp.class);
SessionFactory sf = cfg.buildSessionFactory();
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
System.out.println("File");
Emp objEmp=new Emp();
//objEmp.setEmpNo("1");
objEmp.setEmpName("Guru");
session.save(objEmp);
tx.commit();
session.close();
}
}
regards
Guru
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.