-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Hibernate 5.2.3 was unable to read schema tag
PostPosted: Wed Mar 22, 2017 11:47 am 
Newbie

Joined: Wed Mar 22, 2017 11:33 am
Posts: 3
When we use schema tag in mapping file hibernate5.2.3 unable to find the schema with table name.

Lecturer.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping schema="ACCOUNTING" >
<class name="pojo.Lecturer" table="Lecturer" >
<id name="ID" type="int">
<generator class="increment"/>
</id>
<property name="firstName" column="FName" type="string"/>
<property name="lastName" column="LName" type="string"/>

</class>

</hibernate-mapping>

------------------------------

hibernate.cfg.xml


<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

<property name="hibernate.connection.url">jdbc:sqlserver://IP:1433;databaseName=COLLEGE</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">abc@123</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.current_session_context_class">thread</property>
<mapping resource="Lecturer.hbm.xml" />

</session-factory>
</hibernate-configuration>
------------------------------------------------------------

SimpleTest.java


package test;
import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Restrictions;
import org.hibernate.service.ServiceRegistry;


import pojo.Lecturer;

public class SimpleTest {


public static void main(String[] args) {

SessionFactory sessionFactory = null;

final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure() // configures settings from hibernate.cfg.xml
.build();
try {
sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
}
catch (Exception e) {
// The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
// so destroy it manually.
StandardServiceRegistryBuilder.destroy( registry );
}



Session session = null;

session = sessionFactory.getCurrentSession();

Transaction tx = session.beginTransaction();

Lecturer lecturer1 = new Lecturer();
lecturer1.setFirstName("Appasaheb");
lecturer1.setLastName("Neelawani");



System.out.println
("The lecturer " + lecturer1.getFirstName()+ " "
+ lecturer1.getLastName()+" is successfully added to your database");


Criteria criteria = null;
criteria = session.createCriteria(Lecturer.class);
criteria.add(Restrictions.eq("ID", 11));
List<Lecturer> list = criteria.list();
if(list != null && !list.isEmpty()){
System.out.println(list.get(0).getFirstName());
}


session.save(lecturer1);
tx.commit();

}
}


---------------------------------------------------------------------------------------------------------------------------------------------

Exception


Mar 22, 2017 9:11:14 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 208, SQLState: S0002
Mar 22, 2017 9:11:14 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Invalid object name 'Lecturer'.
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2116)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1899)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1875)
at org.hibernate.loader.Loader.doQuery(Loader.java:919)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336)
at org.hibernate.loader.Loader.doList(Loader.java:2611)
at org.hibernate.loader.Loader.doList(Loader.java:2594)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2423)
at org.hibernate.loader.Loader.list(Loader.java:2418)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:109)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1774)
at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:363)
at test.SimpleTest.main(SimpleTest.java:105)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'Lecturer'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1515)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:404)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:350)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:285)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70)
... 13 more

--------------------------------------------------------------------------------------------------------
The question is when we use schema tag in mapping file hibernate unable to find the schema with table name.

But when we modified the table name tag with schema eg: ACCOUNTING.Lecturer hibernate works properly. Why hibernate not find with schema tag. The same example works fine in hibernate3.

We are in the process of migrating from hibernate3 to hibernate 5.X version.

It will be great help if some one reply as soon as possible.


Thanks in advance


Top
 Profile  
 
 Post subject: Re: Hibernate 5.2.3 was unable to read schema tag
PostPosted: Wed Mar 22, 2017 12:16 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Try to to supply the default schema like this:

Code:
<property name="hibernate.default_schema" value="ACCOUNTING"/>


Top
 Profile  
 
 Post subject: Re: Hibernate 5.2.3 was unable to read schema tag
PostPosted: Thu Mar 23, 2017 2:24 am 
Newbie

Joined: Wed Mar 22, 2017 11:33 am
Posts: 3
Thanks vlad for reply.

In our project we have 5 different schema, by using default schema hibernate trying to use same default schema for all the tables and throwing exception invalid object name for example if have table ASSET.ASSET_NAME then by using default schema hibernate trying to find ACCOUNTING.ASSET_NAME and throws invalid object name exception.


Top
 Profile  
 
 Post subject: Re: Hibernate 5.2.3 was unable to read schema tag
PostPosted: Thu Mar 23, 2017 2:32 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I understand. If you can replicate the issue on Hibernate 5.2.9 with our test case template, you should open a Jira issue and we will investigate it further.


Top
 Profile  
 
 Post subject: Re: Hibernate 5.2.3 was unable to read schema tag
PostPosted: Thu Mar 23, 2017 3:45 am 
Newbie

Joined: Wed Mar 22, 2017 11:33 am
Posts: 3
Yeah we are able to reproduce this issue with hibernate 5.2.9 also.

I am unable to create test case template in the link you provided.


Top
 Profile  
 
 Post subject: Re: Hibernate 5.2.3 was unable to read schema tag
PostPosted: Thu Mar 23, 2017 4:40 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You can use the Hibernate ORM test case templates.

Just provide your mappings and the data access code, and the bootstrap is covered by the test case.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.