aspose file tools*
The moose likes Object Relational Mapping and the fly likes struts1.3 with hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "struts1.3 with hibernate" Watch "struts1.3 with hibernate" New topic
Author

struts1.3 with hibernate

raj jaiswal
Ranch Hand

Joined: Nov 25, 2008
Posts: 56
hi
I am trying to create one Struts1.3 with Hibernate app and accessing a mssql server database.
I am using IBM Rad7.5 tool.

But i am getting exception over there .


public class LoginDao implements LoginInterface {

public void saveUser(UserLogin user) {

System.out.println("I am inside LoginDao class");
Session session = HibernateUtils.currentSession();

System.out.println("is connectioned - " + session.isConnected());
Transaction tx = null;
boolean rollback = true;

try {

session = HibernateUtils.currentSession();
tx = session.beginTransaction();

session.save(user);
tx.commit();
rollback = false;
}

catch (HibernateException e) {
e.printStackTrace();
}
finally {
if( rollback && tx != null){
tx.rollback();
}
HibernateUtils.closeSession();
}

}

When stepping through it with the debugger, if fails in "Transaction tx = session.beginTransaction();" with the following output to the console:

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtils {

private static Log log = LogFactory.getLog(HibernateUtils.class);
private static final SessionFactory sessionFactory;

static {
try {

sessionFactory = new Configuration().configure().buildSessionFactory();

} catch (Throwable ex) {

log.error("Initial SessionFactory creation failed.", ex);
throw new ExceptionInInitializerError(ex);
}
}

public static final ThreadLocal<Session> session = new ThreadLocal<Session>();

public static Session currentSession() throws HibernateException {
System.out.println("before Session s --------- ");
Session s = (Session) session.get();
System.out.println("Session s --------- " +s);

if (s == null) {

s = sessionFactory.openSession();

session.set(s);
}
return s;
}

public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}
}




org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:142)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1353)
at com.emergys.suntyre.InterfaceImplementation.LoginDao.saveUser(LoginDao.java:29)
at com.emergys.suntyre.web.action.LoginAction.execute(LoginAction.java:43)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:735)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The port number 1433/TestDb is not valid.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:170)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:580)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
at java.sql.DriverManager.getConnection(DriverManager.java:311)
at java.sql.DriverManager.getConnection(DriverManager.java:292)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
... 31 more





please find the solution

thanks.


vijin das
Ranch Hand

Joined: Jun 07, 2010
Posts: 129

where you had put your configuration file hibernate.cfg.xml and what about the values you had given in it ...??

the error says like connection to db is not happening (1433/TestDb is not valid. )

just verify that ...


VIJINDAS
raj jaiswal
Ranch Hand

Joined: Nov 25, 2008
Posts: 56
My cfg.xml file is right place and port no. is correct. Still i am getting Error

<?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="show_sql">true</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.connection.url">jdbc:sqlserver://10.10.5.88:1433/TestDb</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">sa</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="hibernate.hbm2ddl.auto">update</property>

<mapping resource="com/emergys/suntyre/pojoMapping/UserLogin.hbm.xml" />


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

Please Solve it.


thanks
Raj jaiswal
vijin das
Ranch Hand

Joined: Jun 07, 2010
Posts: 129

i think it is nothing to do with hibernate ..
its problem with your mssql server database ....
what about your hibernate.connection.url or generically saying the connection string ...
"jdbc:sqlserver://10.10.5.88:1433/TestDb" is having some problem

i think the normal connection string for mssql server is like this

jdbc:sqlserver://:1433;databaseName=;user=;password=; ...

just try changing the connection string like instead of '/' try giving ';' like this

jdbc:microsoft: sqlserver://10.10.5.88:1433;DatabaseName = TestDb ....just try this

am not a mssqlserver guru....
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.
raj jaiswal
Ranch Hand

Joined: Nov 25, 2008
Posts: 56


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That was neither code nor configuration.
vijin das
Ranch Hand

Joined: Jun 07, 2010
Posts: 129

welcome raj ...
take care when you are using code tags ...code tags are meant for putting code or configuration details ...
:D
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts1.3 with hibernate