Zolf
asked on
Hibernate begineer error
Hello there,
I am beginning to learn hibernate and i got my first error and i dont seem to find the cause. the error i get is
Initial SessionFactory creation failed.org.hibernate.Mappi
Exception in thread "main" java.lang.ExceptionInIniti
at src.hib.HibernateUtil.buil
at src.hib.HibernateUtil.<cli
at src.hib.Test.addUser(Test.
at src.hib.Test.main(Test.jav
Caused by: org.hibernate.MappingNotFo
at org.hibernate.cfg.Configur
at org.hibernate.cfg.Configur
at org.hibernate.cfg.Configur
at org.hibernate.cfg.Configur
at org.hibernate.cfg.Configur
at org.hibernate.cfg.Configur
at org.hibernate.cfg.Configur
at src.hib.HibernateUtil.buil
... 3 more
<?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 Oct 25, 2011 9:56:38 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="src.hib.User" table="USER">
<id name="id" type="int">
<column name="ID" />
<generator class="native" />
</id>
<property name="firstName">
<column name="FIRSTNAME" />
</property>
<property name="lastName">
<column name="LASTNAME" />
</property>
</class>
</hibernate-mapping>
==============================================
package src.hib;
public class User
{
private int id;
private String firstName;
private String lastName;
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public String getFirstName()
{
return firstName;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public String getLastName()
{
return lastName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
}
====================================
<?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.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:jtds:sqlserver://localhost:1433;DatabaseName=hibtest</property>
<property name="hibernate.connection.username">test</property>
<property name="hibernate.connection.password">secret=</property>
<property name="hibernate.dialect">custom.java.hibernate.dialect.UnicodeSQLServerDialect</property>
<property name="hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<!-- Mapping files -->
<mapping resource="User.hbm.xml" />
<mapping resource="task.hbm.xml" />
</session-factory>
</hibernate-configuration>
r u running this example in a standalone app or web aplication;
if standalone app check whether mapping files are exists or not in the particular folder
if standalone app check whether mapping files are exists or not in the particular folder
ASKER
>>r u running this example in a standalone app or web aplication;
standalone app
>>if standalone app check whether mapping files are exists or not in the particular folder
it is present
ASKER
ok, i managed to get solve that issue(i had to give the path in the cfg.xml file as well). now i am getting aother error
org.hibernate.exception.Ge
at org.hibernate.exception.SQ
at org.hibernate.exception.SQ
at org.hibernate.exception.JD
at org.hibernate.exception.JD
at org.hibernate.jdbc.Connect
at org.hibernate.jdbc.Connect
at org.hibernate.jdbc.JDBCCon
at org.hibernate.transaction.
at org.hibernate.impl.Session
at src.hib.Test.addUser(Test.
at src.hib.Test.main(Test.jav
Caused by: java.sql.SQLException: Login failed for user 'test'.
at net.sourceforge.jtds.jdbc.
at net.sourceforge.jtds.jdbc.
at net.sourceforge.jtds.jdbc.
at net.sourceforge.jtds.jdbc.
at net.sourceforge.jtds.jdbc.
at net.sourceforge.jtds.jdbc.
at net.sourceforge.jtds.jdbc.
at java.sql.DriverManager.get
at java.sql.DriverManager.get
at org.hibernate.connection.D
at org.hibernate.jdbc.Connect
... 6 more
I think you hibernate.cfg.xml should be in the root of your source and full path to User.hbm.xml and task.hbm.xml should be splled out
if those are in pacakges the path should be reproduces in mapping resource and those xml files should follow the potential java files ofr these
classes
if those are in pacakges the path should be reproduces in mapping resource and those xml files should follow the potential java files ofr these
classes
This is perhaps something with your schema passoword so login to database failed
<mapping resource="src/hib/User.hbm
http://stackoverflow.com/questions/616754/hibernate-how-to-map-a-hbm-xml-file-in-a-different-folder
ASKER
for_yan:
i changed my mapping like this and it worked.thanks for it anyway. but now i am getting login fail error. i am sure i have created this user for the db
<!-- Mapping files -->
<mapping resource="src/hib/User.hbm .xml" />
<mapping resource="src/hib/task.hbm .xml" />
i changed my mapping like this and it worked.thanks for it anyway. but now i am getting login fail error. i am sure i have created this user for the db
<!-- Mapping files -->
<mapping resource="src/hib/User.hbm
<mapping resource="src/hib/task.hbm
can you connect to the same databses with thesame schema outside hibernate ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
don't you have any way to get to that schema form sql prompt ?
If not maybe you can try to write a small progam with jdbc connection with the same credentials
to chek it ?
If not maybe you can try to write a small progam with jdbc connection with the same credentials
to chek it ?
ASKER
cheers,please bear with me i am trying to run my first hibernate app and i am stumbling on the way but getting near. now i get another error
Hibernate:
insert
into
USER
(FIRSTNAME, LASTNAME)
values
(?, ?)
org.hibernate.exception.Ge
at org.hibernate.exception.SQ
at org.hibernate.exception.SQ
at org.hibernate.exception.JD
at org.hibernate.id.insert.Ab
at org.hibernate.persister.en
at org.hibernate.persister.en
at org.hibernate.action.Entit
at org.hibernate.engine.Actio
at org.hibernate.event.def.Ab
at org.hibernate.event.def.Ab
at org.hibernate.event.def.Ab
at org.hibernate.event.def.De
at org.hibernate.event.def.De
at org.hibernate.event.def.De
at org.hibernate.event.def.De
at org.hibernate.event.def.De
at org.hibernate.impl.Session
at org.hibernate.impl.Session
at org.hibernate.impl.Session
at src.hib.Test.addUser(Test.
at src.hib.Test.main(Test.jav
Caused by: java.sql.SQLException: Incorrect syntax near the keyword 'USER'.
at net.sourceforge.jtds.jdbc.
at net.sourceforge.jtds.jdbc.
at net.sourceforge.jtds.jdbc.
at net.sourceforge.jtds.jdbc.
at net.sourceforge.jtds.jdbc.
at net.sourceforge.jtds.jdbc.
at net.sourceforge.jtds.jdbc.
at org.hibernate.id.IdentityG
at org.hibernate.id.insert.Ab
... 17 more
Exception in thread "main" org.hibernate.AssertionFai
at org.hibernate.event.def.De
at org.hibernate.event.def.De
at org.hibernate.event.def.De
at org.hibernate.event.def.Ab
at org.hibernate.event.def.Ab
at org.hibernate.event.def.De
at org.hibernate.impl.Session
at src.hib.Test.addUser(Test.
at src.hib.Test.main(Test.jav
i think in USER table id is mandatory.check columns..
insert
into
USER
(id,FIRSTNAME, LASTNAME)
values
(1,?, ?)
Was it hibernate who was supposed to create the table ?
If so, can you check indpendently if the table was created ?
If so, can you check indpendently if the table was created ?
ASKER
chaituu:
in the db, only one table is created and is called TASK,the other table USER has not been created. the table TASK is empty
either create table USER with columns ID,FIRSTNAME,LASTNAME or change the
<class name="src.hib.User" table="TASK">
<class name="src.hib.User" table="TASK">
That is strange - maybe some problem in User.hbm.xml
does it matter that this is upper case, another is lower case in the xml name of the faile?
It probably should not matter
does it matter that this is upper case, another is lower case in the xml name of the faile?
It probably should not matter
in table TASK create column names..
ASKER
in table TASK create column names..
what do you mean
ASKER
ok,got it. MSSQL does not like to have a table by the name USER, i changed it to USERS and it worked.phew,at last managed to run my first hibernate app
great..
very good! Yes, inedeed USER is reserved word in mand db
ASKER
cheers
currently where did u place this files?