• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

problem with namingstrategy

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Am a newbie to hibernate and i've been trying to figure out whats wrong with one of my starters.

My mapping file looks like this :

<?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 package="com.kartik.example">
<class name="Employee" table="EMPLOYEE_TBL">
<id name="empId">
<generator class="native" />
</id>
<property name="age"/>
<property name="name"/>
</class>
</hibernate-mapping>

The hibernate.properties file that i employ is:

hibernate.dialect= org.hibernate.dialect.SQLServerDialect
hibernate.connection.driver_class= com.microsoft.jdbc.sqlserver.SQLServerDriver
hibernate.connection.url= jdbc:microsoft:sqlserver://localhost:1433
hibernate.connection.username= sa
hibernate.connection.password= sa
hibernate.hbm2ddl.auto=create
hibernate.show_sql= true

Db is SQL server 2k. I get an exception while trying to insert a record into the employee table using the following code::

Properties propFileContents = new Properties();
propFileContents.load(HibernateSample.class.getResourceAsStream
("hibernate.properties"));
Configuration cfg= new Configuration()
.setNamingStrategy(ImprovedNamingStrategy.INSTANCE)
.addResource("employee.hbm.xml")
.setProperties(propFileContents);

The exception is (am mgiving the main stuff alone here):

Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [com.kartik.example.Employee]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
.....
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid object name 'employee_tbl'.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
....


Pls note that i have not created the table Employee in the db yet and i hope the property hibernate.hbm2.ddl_auto=create would take care of that.

Can someone pls help me out

Thanks,
Kartik
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that there is no DB selected or the wrong DB is selected.
User sa ususally has a standard schema.
You can select the DB via the connection url or create a new db user and set a standard schema for him.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic