Hi,
I'm searching for a persistence framework to use, and actually I try to test hibernate.
My problem at the moment is that i get a NullPointerException if I make a lookup.
In the JNDI VIEW page i found the entry:
+- SessionFactory (class: org.hibernate.impl.SessionFactoryImpl)
But in the log file I found these entries, and i don't know what to do now.
Code:
[b]server.log:[/b]
...
[org.hibernate.impl.SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
...
[org.jboss.hibernate.jmx.Hibernate] SessionFactory successfully built and bound into JNDI [SessionFactory]
...
Code:
[b]hibernate-service.xml:[/b]
<server>
<mbean code="org.jboss.hibernate.jmx.Hibernate" name="jboss.har:service=Hibernate">
<attribute name="DatasourceName">java:/DefaultDS</attribute>
<attribute name="Dialect">org.hibernate.dialect.Oracle9Dialect</attribute>
<property name="hibernate.default_schema">LAGERDBA</property>
<property name="connection.pool_size">1</property>
<property name="show_sql">true</property>
<attribute name="SessionFactoryName">SessionFactory</attribute>
<attribute name="CacheProviderClass">org.hibernate.cache.HashtableCacheProvider</attribute>
<attribute name="ShowSqlEnabled">true</attribute>
</mbean>
</server>
Code:
[b]UserManager.java[/b]
...
InitialContext ctx = new InitialContext();
SessionFactory factory;
factory = (SessionFactory) ctx.lookup("SessionFactory");
Session hsession = factory.openSession();
Transaction tx = hsession.beginTransaction();
...
Sample Hibernate File
Code:
[b]AcUser.java[/b]
package de.psb_gmbh.main.business.persistence.hibernate;
import java.util.Set;
public class AcUser implements java.io.Serializable {
// Fields
private String UserId;
private AcGroup AcGroup;
private String LoginName;
private String Name;
private String Password;
private Integer CheckCount;
private Set<AcUserToGroup> SetOfAcUserToGroup;
// Constructors
public AcUser() {
}
// Property accessors
public String getUserId() {
return this.UserId;
}
public void setUserId(String UserId) {
this.UserId = UserId;
}
public AcGroup getAcGroup() {
return this.AcGroup;
}
public void setAcGroup(AcGroup AcGroup) {
this.AcGroup = AcGroup;
}
public String getLoginName() {
return this.LoginName;
}
public void setLoginName(String LoginName) {
this.LoginName = LoginName;
}
public String getName() {
return this.Name;
}
public void setName(String Name) {
this.Name = Name;
}
public String getPassword() {
return this.Password;
}
public void setPassword(String Password) {
this.Password = Password;
}
public Integer getCheckCount() {
return this.CheckCount;
}
public void setCheckCount(Integer CheckCount) {
this.CheckCount = CheckCount;
}
public Set<AcUserToGroup> getSetOfAcUserToGroup() {
return this.SetOfAcUserToGroup;
}
public void setSetOfAcUserToGroup(Set<AcUserToGroup> setOfAcUserToGroup) {
this.SetOfAcUserToGroup = setOfAcUserToGroup;
}
}
Code:
[b]AcUser.hbm.xml[/b]
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="de.psb_gmbh.main.business.persistence.hibernate.AcUser" table="AC_USER" schema="LAGERDBA">
<id name="UserId">
<column name="USER_ID"/>
<generator class="assigned" />
</id>
<many-to-one name="AcGroup" class="de.psb_gmbh.main.business.persistence.hibernate.AcGroup">
<column name="MASTER_GROUP_ID"/>
</many-to-one>
<property name="LoginName">
<column name="LOGIN_NAME"/>
</property>
<property name="Name">
<column name="NAME"/>
</property>
<property name="Password">
<column name="PASSWORD"/>
</property>
<property name="CheckCount">
<column name="CHECK_COUNT"/>
</property>
<set name="SetOfAcUserToGroup">
<key>
<column name="USER_ID" />
</key>
<one-to-many class="de.psb_gmbh.main.business.persistence.hibernate.AcUserToGroup" />
</set>
</class>
</hibernate-mapping>
I'm using
- JBoss 4.0.2
- Hibernate 3.0.5
- Java 5.0
- Oracle DB 9.2
- Windows XP SP1
- Eclipse 3.1M7 with MyEclipse 3.8.4, JBoss IDE1.5M1, XML Spy Pro 2005
THANKS!