I am using Hibernate4 with Spring and I am trying to map a Term class to a Document class. A term may occur in many documents and a document can contain many terms. I have read up on this, and I have attempted a number of fixes, including overriding the equals and hashCode methods.
In my database the terms and documents are stored in separated tables mediated by a relationship table. In the code here, it is called the jtable. I am using hibernates many-to-many mapping, but every time that I try to fetch a term object it simply deletes the row in the relationship table.
Here is a sample sql output that hibernate's show sql is giving out:
Hibernate: SELECT * FROM tags WHERE token='rose'
Hibernate: delete from jtable where tag_id=?
Here are the relevant classes and configs:
public class Term {
public String getWord() {
return word;
}
public void setWord(String word) {
this.word = word;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Set<Document> getDocuments() {
return documents;
}
public void setDocuments(Set<Document> documents) {
documents = documents;
}
#Override
public boolean equals(Object obj) {
if(obj.getClass() != getClass()){
return false;
}
Term term = (Term) obj;
if (hashCode() == term.hashCode()){
return true;
}
return false;
}
#Override
public int hashCode(){
return word.hashCode();
}
private String word;
private int id;
private Set<Document> documents = new HashSet<Document>();
}
And the Document class :
public class Document implements Comparable<Document> {
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public URL getUrl() {
return url;
}
public void setUrl(URL url) {
this.url = url;
}
public Integer getLength() {
return length;
}
public void setLength(Integer length) {
this.length = length;
}
public Double getRank() {
return rank;
}
public void setRank(Double rank) {
this.rank = rank;
}
#Override
public boolean equals(Object obj) {
if(obj.getClass() != getClass()){
return false;
}
Document document = (Document) obj;
if (hashCode() == document.hashCode()){
return true;
}
return false;
}
#Override
public int hashCode(){
int hash = 1;
hash *= 1 + (length == null ? 0 :length);
hash *= 2 + (rank == null ? 0 :rank);
hash *= 3 + (title == null ? 0 : title.hashCode());
hash *= 4 + (url.hashCode());
return hash;
}
#Override
public int compareTo(Document document) {
return rank.compareTo(document.getRank());
}
private int id;
private Integer length;
private Double rank;
private String title;
private URL url;
}
Document.hbm.xml
<?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="package.Document" table="documents">
<id name="id" type="java.lang.Integer">
<column name="document_id" />
<generator class="native" />
</id>
<property name="title" type="java.lang.String">
<column name="title" length="255" not-null="false" />
</property>
<property name="length">
<column name="length" not-null="false"/>
</property>
<property name="rank" type="java.lang.Double">
<column name="rank" not-null="false" />
</property>
<property name="url" type="org.hibernate.type.UrlType">
<column name="url" length="255" not-null="false" />
</property>
</class>
</hibernate-mapping>
Term.hbm.xml
<?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="package.Term" table="tags">
<id name="id" type="java.lang.Integer">
<column name="tag_id" />
<generator class="native" />
</id>
<property name="word" type="string">
<column name="token" not-null="true" unique="true" />
</property>
<set name="documents" table="jtable"
inverse="false" lazy="true" fetch="select" cascade="all" >
<key>
<column name="tag_id" not-null="true" />
</key>
<many-to-many entity-name="package.Document">
<column name="document_id" not-null="true" />
</many-to-many>
</set>
</class>
</hibernate-mapping>
And the relevant context config section:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${database.driver}"/>
<property name="url" value="${database.url}"/>
<property name="username" value="${database.user}"/>
<property name="password" value="${database.password}"/>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>Document.hbm.xml</value>
<value>Term.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
</props>
</property>
</bean>
I have been looking at this error for a while, so any answers would be appreciated.
Related
I'm working for several hours on this issue about hibernate mapping. I think the error could be a simple syntax mistake but I can't find it!!!
I ran into the following exception when I executed my code:
Initial SessionFactory creation failed.org.hibernate.MappingException: entity class not found: LegalFee
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.plm.dao.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:33)
at com.plm.dao.util.HibernateUtil.getSessionFactory(HibernateUtil.java:39)
at com.plm.dao.AppTest.main(AppTest.java:15)
Firstly, I'm using hibernate 4.2 with Java 8 and MariaDB 10.
See all configurations below.
My hibernate.cfg.xml, I removed C3P0 configuration:
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name='connection.driver_class'>com.mysql.jdbc.Driver</property>
<property name='connection.url'>jdbc:mysql://localhost:3306/PokerLeagueManager</property>
<property name='connection.username'>root</property>
<property name='connection.password'>mypassword</property>
<property name="show_sql">true</property>
<!-- SQL dialect -->
<property name='dialect'>org.hibernate.dialect.MySQL5InnoDBDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name='show_sql'>true</property>
<mapping resource="mappings/BlindStructure.hbm.xml"/>
<mapping resource="mappings/Tournament.hbm.xml"/>
<mapping resource="mappings/LegalFee.hbm.xml"/>
</session-factory>
</hibernate-configuration>
The error is on LegalFee bean so focus on it.
See the sql table creation of legalFee:
CREATE TABLE `legalFee` (
`idFee` int(11) NOT NULL,
`shortName` varchar(50) NOT NULL,
`description` varchar(200) DEFAULT NULL,
`feePercent` int(11) DEFAULT NULL,
`feeFixed` int(11) DEFAULT NULL,
PRIMARY KEY (`idFee`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
The class :
public class LegalFee implements Serializable {
/**
* generated serial uid
*/
private static final long serialVersionUID = -2259355205530727294L;
private int idFee;
private String shortName;
private String description;
private Integer feePercent;
private Integer feeFixed;
private Set<Tournament> tournaments = new HashSet<Tournament>(0);
public LegalFee() {
}
public LegalFee(int idFee, String shortName) {
this.idFee = idFee;
this.shortName = shortName;
}
public LegalFee(int idFee, String shortName, String description,
Integer feePercent, Integer feeFixed, Set<Tournament> tournaments) {
this.idFee = idFee;
this.shortName = shortName;
this.description = description;
this.feePercent = feePercent;
this.feeFixed = feeFixed;
this.tournaments = tournaments;
}
public int getIdFee() {
return this.idFee;
}
public void setIdFee(int idFee) {
this.idFee = idFee;
}
public String getShortName() {
return this.shortName;
}
public void setShortName(String shortName) {
this.shortName = shortName;
}
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getFeePercent() {
return this.feePercent;
}
public void setFeePercent(Integer feePercent) {
this.feePercent = feePercent;
}
public Integer getFeeFixed() {
return this.feeFixed;
}
public void setFeeFixed(Integer feeFixed) {
this.feeFixed = feeFixed;
}
public Set<Tournament> getTournaments() {
return this.tournaments;
}
public void setTournaments(Set<Tournament> tournaments) {
this.tournaments = tournaments;
}
}
And lastly the LegalFee.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="LegalFee" table="legalFee" catalog="PokerLeagueManager" optimistic-lock="version">
<id name="idFee" type="int">
<column name="idFee" />
<generator class="identity" />
</id>
<property name="shortName" type="string">
<column name="shortName" length="50" not-null="true" />
</property>
<property name="description" type="string">
<column name="description" length="200" />
</property>
<property name="feePercent" type="java.lang.Integer">
<column name="feePercent" />
</property>
<property name="feeFixed" type="java.lang.Integer">
<column name="feeFixed" />
</property>
<set name="tournaments" table="tournament" inverse="true" lazy="true" fetch="select">
<key>
<column name="legalFee_feeId" />
</key>
<one-to-many class="Tournament" />
</set>
</class>
</hibernate-mapping>
Thanks for your help.
If your LegalFee class is not in default package you need to provide the fully classified name of the class.
e.g "class name="com.abc.xyx.LegalFee" table="legalFee" "
Criteria cr=session.createCriteria(Student.class).add(Restrictions.between("strStudentMark1", "90", "100"));
In the above code snippet, I have given the mark between 90 and 100. In the Student table, there are fields between marks 90 and 100. but am not getting those in the output.
What could be the problem? Am I making any mistake?
EDIT
Yes am getting the whole list when I run.
Criteria cr=session.createCriteria(Student.class);
Student entity is below with generated Getters and Setters.
import java.io.Serializable;
public class Student implements Serializable {
private String strStudentID;
private String strStudentRegNO;
private String strStudentName;
private String strStudentMark1;
private String strStudentMark2;
private String strStudentDegree;
private String strStudentMobileNO;
private String strStudentMailID;
private String strSalary;
public String getStrSalary() {
return strSalary;
}
public void setStrSalary(String strSalary) {
this.strSalary = strSalary;
}
public String getStrStudentID() {
return strStudentID;
}
public void setStrStudentID(String strStudentID) {
this.strStudentID = strStudentID;
}
public String getStrStudentRegNO() {
return strStudentRegNO;
}
public void setStrStudentRegNO(String strStudentRegNO) {
this.strStudentRegNO = strStudentRegNO;
}
public String getStrStudentName() {
return strStudentName;
}
public void setStrStudentName(String strStudentName) {
this.strStudentName = strStudentName;
}
public String getStrStudentMark1() {
return strStudentMark1;
}
public void setStrStudentMark1(String strStudentMark1) {
this.strStudentMark1 = strStudentMark1;
}
public String getStrStudentMark2() {
return strStudentMark2;
}
public void setStrStudentMark2(String strStudentMark2) {
this.strStudentMark2 = strStudentMark2;
}
public String getStrStudentDegree() {
return strStudentDegree;
}
public void setStrStudentDegree(String strStudentDegree) {
this.strStudentDegree = strStudentDegree;
}
public String getStrStudentMobileNO() {
return strStudentMobileNO;
}
public void setStrStudentMobileNO(String strStudentMobileNO) {
this.strStudentMobileNO = strStudentMobileNO;
}
public String getStrStudentMailID() {
return strStudentMailID;
}
public void setStrStudentMailID(String strStudentMailID) {
this.strStudentMailID = strStudentMailID;
}
}
hibernate.cfg.xml.
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:#aaaa:bbbb</property>
<property name="connection.username">xxx</property>
<property name="connection.password">yyy</property>
<!-- <property name="connection.pool_size">5</property> -->
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<property name="current_session_context_class">thread</property>
<!-- <property name="hbm2ddl.auto">update</property> -->
<mapping resource="com/hibresources/Student.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Student.hbm.xml.
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 17 Dec, 2010 5:54:42 AM by Hibernate Tools 3.3.0.GA -->
<hibernate-mapping>
<class name="com.bean.Student" table="STUDENT">
<meta attribute="class-description">
This class has details abt Students
</meta>
<id name="strStudentID" >
<column name="STUID" />
</id>
<property name="strStudentRegNO" >
<column name="STUREG_NO" />
</property>
<property name="strStudentName" >
<column name="STUNAME" />
</property>
<property name="strStudentMark1" >
<column name="STUMARK1" />
</property>
<property name="strStudentMark2" >
<column name="STUMARK2" />
</property>
<property name="strStudentDegree" >
<column name="DEGREE" />
</property>
<property name="strStudentMobileNO" >
<column name="MOBILENO" />
</property>
<property name="strStudentMailID" >
<column name="MAILID" />
</property>
<property name="strSalary" >
<column name="SALARY" />
</property>
</class>
</hibernate-mapping>
Please make sure that the data stored in the Database is an INT. The between will only work with INT Datatype. Also try passing the value as int in code.
I have this table in mysql:
CREATE TABLE IF NOT EXISTS `realEstate`.`USER` (
`userID` INT NOT NULL AUTO_INCREMENT,
`username` VARCHAR(45) NULL,
`password` VARCHAR(45) NULL,
`registrationDate` VARCHAR(15) NULL,
`name` VARCHAR(45) NULL,
`surname` VARCHAR(45) NULL,
`phone` VARCHAR(45) NULL,
`email` VARCHAR(45) NULL,
`registered` TINYINT(1) NULL,
PRIMARY KEY (`userID`),
UNIQUE INDEX `user_id_UNIQUE` (`userID` ASC))
ENGINE = InnoDB;
and I try to get all its contents with hibernate. Althoug I implemented the .hbm file I get the error that the USER is not mapped[from USER]. Here how I make the question:
List<Users> users = null;
Session session = null;
Transaction transaction = null;
try {
SessionFactory factory = HibernateUtil.getSessionFactory();
session = factory.getCurrentSession();
transaction = session.beginTransaction();
Query query = session.createQuery("from USER");
users = query.list();
transaction.commit();
} catch (HibernateException ex) {
System.out.println("Exception:");
System.out.println(ex.getMessage());
if (transaction != null) {
transaction.rollback();
}
} finally {
/*for(Users user:users){
System.out.println(user.getName());
}*/
}
System.out.println("Complete");
and here is the users.hbm.xml
<?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="Users" table="USER">
<id name="userID" type="int">
<column name="userID" />
<generator class="assigned" />
</id>
<property name="username" type="java.lang.String">
<column name="username" length="45"/>
</property>
<property name="password" type="java.lang.String">
<column name="password" length="45" />
</property>
<property name="name" type="java.lang.String">
<column name="name" length="45"/>
</property>
<property name="date" type="java.lang.String">
<column name="registrationDate" length="45"/>
</property>
<property name="surname" type="java.lang.String">
<column name="surname" length="45"/>
</property>
<property name="phone" type="java.lang.String">
<column name="phone" length="45"/>
</property>
<property name="email" type="java.lang.String">
<column name="email" length="45"/>
</property>
<property name="registered" type="boolean">
<column name="registered" />
</property>
</class>
</hibernate-mapping>
Eveyrything seems fine to me, but it doesn't work. Can you help me?
Here's the class Users:
public class Users {
private int user_id;
private String username;
private String password;
private String date;
private String name;
private String surname;
private String phone;
private String email;
private boolean registered;
public int getuserID() {
return user_id;
}
public void setuserID(int user_id) {
this.user_id = user_id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public boolean getRegistered() {
return registered;
}
public void setRegistered(boolean registered) {
this.registered = registered;
}
}
here's the hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="session1">
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/realestate</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<mapping resource="users.hbm.xml"/>
<mapping resource="adminstrator.hbm.xml"/>
</session-factory>
</hibernate-configuration>
and here's the directory
In the HQL , you should use the java class name and property name of the mapped Entity instead of the actual table name and column name , so the HQL should be :
Query query = session.createQuery("from USERS");
as provided by you in users.hbm.xml
This is my first post in stackoverflow:
I am new to hibernate, infact below is my first code in hibernate:
i am repetedly getting "could not parse mapping document" error, when i run my main class.
below is the code for your refernce, please help me out of this.
Config file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
<property name="hibernate.connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
<property name="hibernate.connection.url">jdbc:derby://localhost:1527/sample</property>
<property name="hibernate.connection.username">one</property>
<property name="hibernate.connection.password">two</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.current_session_context_class">thread</property>
<mapping resource="EmployeeMapping.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Mapping file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Employee" table="EMPLOYEE"/>
<id name="emp_id" type="int" column="emp_id"/>
<property name="emp_name">
<column name="emp_name"/>
</property>
<property name="emp_branch">
<column name="emp_branch"/>
</property>
<property name="emp_Salary">
<column name="emp_salary"/>
</property>
<property name="emp_fav_dgt">
<column name="emp_fav_dgt"/>
</property>
</hibernate-mapping>
Pojo class:
public class Employee {
private int emp_id;
private String emp_name;
private String emp_branch;
private int emp_Salary;
private int emp_fav_dgt;
public int getEmp_Salary() {
return emp_Salary;
}
public void setEmp_Salary(int emp_Salary) {
this.emp_Salary = emp_Salary;
}
public String getEmp_branch() {
return emp_branch;
}
public void setEmp_branch(String emp_branch) {
this.emp_branch = emp_branch;
}
public int getEmp_fav_dgt() {
return emp_fav_dgt;
}
public void setEmp_fav_dgt(int emp_fav_dgt) {
this.emp_fav_dgt = emp_fav_dgt;
}
public int getEmp_id() {
return emp_id;
}
public void setEmp_id(int emp_id) {
this.emp_id = emp_id;
}
public String getEmp_name() {
return emp_name;
}
public void setEmp_name(String emp_name) {
this.emp_name = emp_name;
}
}
Main class:
public class Main {
public static void main(String[] args) {
System.out.println("asdf");
SessionFactory sessionFactory = null;
Transaction ts = null;
Session session = null;
Configuration conf = null;
try{
conf = new org.hibernate.cfg.Configuration().configure();
sessionFactory = conf.buildSessionFactory();
session =sessionFactory.openSession();
Employee customer = new Employee();
customer.setEmp_id(1);
customer.setEmp_name("one");
customer.setEmp_branch("old");
customer.setEmp_Salary(1000);
customer.setEmp_fav_dgt(2);
session.save(customer);
ts.commit();
}
catch(Exception e){
e.printStackTrace();;
}
finally{
session.close();
}
}
}
The property tags corresponding with the fields should be nested within the class tag.
<class name="Employee" table="EMPLOYEE">
<id name="emp_id" type="int" column="emp_id"/>
<property name="emp_name">
<column name="emp_name"/>
</property>
<property name="emp_branch">
<column name="emp_branch"/>
</property>
<property name="emp_Salary">
<column name="emp_salary"/>
</property>
<property name="emp_fav_dgt">
<column name="emp_fav_dgt"/>
</property>
</class>
i am new in using hibernate and for some reason i am getting a list of null objects when i am using the following code:
public static void main(String args[])
{
Session s = HibernateUtil.currentSession();
ArrayList lst = (ArrayList) s.createQuery("from Users").list();
for(Object obj : lst){
Users user = (Users)obj;
System.Out.println(user.getUserid()); // null
}
}
my hibernate mapping xml looks like this:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 27, 2012 9:48:45 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="us.Users" table="USERS">
<id name="userid" type="int">
<column name="USERID" precision="9" scale="0" />
<generator class="assigned" />
</id>
<property name="username" type="string">
<column name="USERNAME" length="200" />
</property>
<property name="password" type="string">
<column name="PASSWORD" length="200" />
</property>
<property name="firstName" type="string">
<column name="FIRST_NAME" length="200" />
</property>
<property name="lastName" type="string">
<column name="LAST_NAME" length="200" />
</property>
<property name="dateOfBirth" type="timestamp"> // my guess was that the problem appears with the timestamp property
<column name="DATE_OF_BIRTH" />
</property>
<property name="registrationDate" type="timestamp">
<column name="REGISTRATION_DATE" />
</property>
<one-to-one name="administrators" class="assignment2.Administrators"></one-to-one>
<set name="histories" table="HISTORY" inverse="true" lazy="false" fetch="select">
<key>
<column name="USERID" precision="9" scale="0" not-null="true" />
</key>
<one-to-many class="us.History" />
</set>
<set name="loginlogs" table="LOGINLOG" inverse="true" lazy="false" fetch="select">
<key>
<column name="USERID" precision="9" scale="0" not-null="true" />
</key>
<one-to-many class="us.Loginlog" />
</set>
</class>
here is my hibernate.cfg.xml :
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.password">abcd</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:#localhost:1521:xe</property>
<property name="hibernate.connection.username">SYSTEM</property>
<property name="hibernate.default_schema">SYSTEM</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.search.autoregister_listeners">false</property>
<mapping resource="assignment2/History.hbm.xml" />
<mapping resource="assignment2/Similarity.hbm.xml" />
<mapping resource="assignment2/Loginlog.hbm.xml" />
<mapping resource="assignment2/Users.hbm.xml" />
<mapping resource="assignment2/Administrators.hbm.xml" />
<mapping resource="assignment2/Mediaitems.hbm.xml" />
</session-factory>
and the users class:
/**
* Users generated by hbm2java
*/
public class Users implements java.io.Serializable {
private int userid;
private String username;
private String password;
private String firstName;
private String lastName;
private Date dateOfBirth;
private Date registrationDate;
private Administrators administrators;
private Set<History> histories = new HashSet<History>(0);
private Set<Loginlog> loginlogs = new HashSet<Loginlog>(0);
public Users() {
}
public Users(int userid) {
this.userid = userid;
}
public Users(int userid, String username, String password,
String firstName, String lastName, Serializable dateOfBirth,
Serializable registrationDate, Administrators administrators,
Set<History> histories, Set<Loginlog> loginlogs) {
this.userid = userid;
this.username = username;
this.password = password;
this.firstName = firstName;
this.lastName = lastName;
this.dateOfBirth = dateOfBirth;
this.registrationDate = registrationDate;
this.administrators = administrators;
this.histories = histories;
this.loginlogs = loginlogs;
}
public int getUserid() {
return this.userid;
}
public void setUserid(int userid) {
this.userid = userid;
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Date getDateOfBirth() {
return this.dateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public Date getRegistrationDate() {
return this.registrationDate;
}
public void setRegistrationDate(Date registrationDate) {
this.registrationDate = registrationDate;
}
public Administrators getAdministrators() {
return this.administrators;
}
public void setAdministrators(Administrators administrators) {
this.administrators = administrators;
}
public Set<History> getHistories() {
return this.histories;
}
public void setHistories(Set<History> histories) {
this.histories = histories;
}
public Set<Loginlog> getLoginlogs() {
return this.loginlogs;
}
public void setLoginlogs(Set<Loginlog> loginlogs) {
this.loginlogs = loginlogs;
}
}
thanks alot in advance