-->
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.  [ 3 posts ] 
Author Message
 Post subject: Authorization with Resin and MySQL.
PostPosted: Tue Dec 14, 2004 5:57 am 
Newbie

Joined: Tue Dec 14, 2004 5:41 am
Posts: 3
Hi

I have a problem whereby Hibernate will not authorize with MySQL. I have JNDI connection defined in Resin 3.0.9 as follows:

<database>
<jndi-name>jdbc/ssweb</jndi-name>
<driver type="org.gjt.mm.mysql.Driver">
<url>jdbc:mysql://127.0.0.1:3306/ssweb</url>
<user>testuser</user>
<password>password</password>
</driver>
<prepared-statement-cache-size>8</prepared-statement-cache-size>
<max-connections>20</max-connections>
<max-idle-time>30s</max-idle-time>
</database>

I am using Hibernate version 2.1.7 and have defined the session factory as follows:

<hibernate-configuration>
<session-factory>
<property name="connection.datasource">java:comp/env/jdbc/ssweb</property>
<property name="show_sql">true</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<mapping resource="data/Customer.hbm.xml"/>
</session-factory>
</hibernate-configuration>

I can connect to the database without a problem using standard Java as follows:

<%
Context c = new InitialContext();
DataSource d=(DataSource)c.lookup("java:comp/env/jdbc/ssweb");
Connection cn=d.getConnection();
PreparedStatement ps=cn.prepareStatement("SELECT * FROM Customers");
ResultSet rs=ps.executeQuery();
while (rs.next()) {
out.println(rs.getString("firstName"));
}
rs.close();
cn.close();
%>

however when I try to use Hibernate with:

<%@page import="java.util.Iterator, ss.app.*, ss.data.*,net.sf.hibernate.*"%>
<%
net.sf.hibernate.Session s= HibernateHelper.currentSession();
Transaction tx=s.beginTransaction();
Customer c=new Customer();
c.setLogon("tester");
c.setFirstName("Test");
c.setLastName("Customer");
s.save(c);
tx.commit();
tx = s.beginTransaction();
Query query=s.createQuery("select * from Csutomers");
for (Iterator it=query.iterate(); it.hasNext();) {
c = (Customer) it.next();
out.println("Customer: " + c.getFirstName() );
}
tx.commit();
%>

I get the following error:

java.sql.SQLException: Invalid authorization specification message from
server: "Access denied for user 'sa'@'localhost' (using password: NO)"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1906)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:2520)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:817)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1786)
at com.mysql.jdbc.Connection.<init>(Connection.java:450)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
at com.caucho.sql.DriverConfig.createDriverConnection(DriverConfig.java:448)
at com.caucho.sql.ManagedConnectionImpl.initDriverConnection(ManagedConnectionImpl.java:236)
at com.caucho.sql.ManagedConnectionImpl.<init>(ManagedConnectionImpl.java:133)
at com.caucho.sql.ManagedFactoryImpl.createManagedConnection(ManagedFactoryImpl.java:122)
at com.caucho.jca.ConnectionPool.create(ConnectionPool.java:791)
at com.caucho.jca.ConnectionPool.allocatePool(ConnectionPool.java:661)
at com.caucho.jca.ConnectionPool.allocate(ConnectionPool.java:618)
at com.caucho.jca.ConnectionPool.allocateConnection(ConnectionPool.java:515)
at com.caucho.sql.DataSourceImpl.getConnection(DataSourceImpl.java:95)
at com.caucho.sql.DBPool.getConnection(DBPool.java:549)
at net.sf.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:56)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:289)
at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3361)
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3321)
at net.sf.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:40)
at net.sf.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransactionFactory.java:19)
at net.sf.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:2251)
at _jsp._hibertest__jsp._jspService(/hibertest.jsp:4)
at com.caucho.jsp.JavaPage.service(JavaPage.java:61)
at com.caucho.jsp.Page.pageservice(Page.java:557)
at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:141)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:163)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:207)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:249)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:327)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:450)
at com.caucho.util.ThreadPool.run(ThreadPool.java:394)
at java.lang.Thread.run(Thread.java:595)

Any ideas???

Thanks
Dave


Top
 Profile  
 
 Post subject: Some missing info
PostPosted: Tue Dec 14, 2004 7:29 am 
Newbie

Joined: Tue Dec 14, 2004 5:41 am
Posts: 3
Noriced somemissing info.

The database is MySQL version 4.1.7.

The mapping file is:

<hibernate-mapping>

<class name="ss.app.Customer" table="Customers">

<id name="id" type="int" unsaved-value="null" >
<column name="id" sql-type="integer" not-null="true" auto-inc="true"/>
</id>

<property name="logon">
<column name="logon" sql-type="varchar" length="45" not-null="true" auto-inc="false"/>
</property>

<property name="firstName">
<column name="firstName" sql-type="varchar" length="45" not-null="true" auto-inc="false"/>
</property>

<property name="lastName">
<column name="lastName" sql-type="varchar" length="45" not-null="true" auto-inc="false"/>
</property>

</class>

</hibernate-mapping>

and the sessionfactory code is:

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;

public class HibernateHelper {

private static final SessionFactory sessionFactory;

static {
try {
// Create the SessionFactory
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
}

public static final ThreadLocal session = new ThreadLocal();

public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
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();
}
}


Any help greatly appreciated!

Thanks
Dave


Top
 Profile  
 
 Post subject: Fixed it...
PostPosted: Tue Dec 14, 2004 9:08 am 
Newbie

Joined: Tue Dec 14, 2004 5:41 am
Posts: 3
Brain must have been switched off! There was still a HypersonicSQL datasource configured which seemed to override my MySQL one...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.