• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RE: accessing database using JNDI

 
Srikanth Tasupalli
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi... I am not able to access the database using JNDI name specified in hibernate.cfg.xml. Its failing to create a connection, but the DataSource is available.
Below are the changes made. Any response would be really helpful...Thanks

Following is the error message:

Caused by: org.jboss.resource.JBossResourceException: Apparently wrong driver class specified for URL: class: com.mysql.jdbc.Driver, url: jdbc:mysql//localhost:3306/hibernate

hibernate.cfg.xml

<?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 name="java:/hibernate/HibernateFactory">

<property name="hibernate.connection.datasource">java:jdbc/MySQL</property>
<property name="hibernate.transaction.manager_lookup_class">net.sf.hibernate.transaction.JBossTransactionManagerLookup</property>
<property name="hibernate.session_factory_name">hibernate/HibernateFactory</property>
<property name="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>

<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">120</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statements">50</property>

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:mysql//localhost:3306/hibernate</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">MySQLDialect</property>
<property name="show-sql">true</property>

<mapping resource="com/Cavatier/Classes/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>


mysql-ds.xml

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>jdbc/MySQL</jndi-name>
<connection-url>jdbc:mysql//localhost:3306/hibernate</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password>root</password>
</local-tx-datasource>
</datasources>


java code accessing the database:


Configuration cfg = new Configuration();
//cfg.addResource("com/Cavatier/Classes/User.hbm.xml");

PrintWriter pw = response.getWriter();
pw.println("Entered Servlet");

cfg.configure();

PersistentClass UserMappng= cfg.getClassMapping
("com.Cavatier.Classes.User");

System.err.println("----UserMapping--------"+UserMappng);

Column column = new Column();
column.setName("MOTTO");
column.setNullable(false);
column.setUnique(true);

UserMappng.getTable().addColumn(column);

SimpleValue value = new SimpleValue();
value.setTable(UserMappng.getTable());
value.addColumn(column);
value.setTypeName(String.class.getName());




Property prop = new Property();
prop.setName("motto");
prop.setValue(value);

UserMappng.addProperty(prop);


SessionFactory sf = cfg.buildSessionFactory();
ClassMetadata meta = sf.getClassMetadata(User.class);
String[] metaPropertyNames = meta.getPropertyNames();
Object[] propertyValues = meta
.getPropertyValues(User.class, EntityMode.POJO);

for (int i = 0; i < metaPropertyNames.length; i++) {

pw.println("----metaPropertyNames --- "+ metaPropertyNames[i]);
pw.println("----propertyValues --- "+propertyValues[i]);

System.out.println("----metaPropertyNames --- "+ metaPropertyNames[i]);
System.out.println("-----propertyValues --- "+propertyValues[i]);

}

pw.println(cfg.getClassMapping("User.class"));
System.out.println(cfg.getClassMapping("User.class"));






 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

jdbc:mysql//localhost:3306/hibernate

This URL is wrong. You are missing a colon after mysql.
 
Srikanth Tasupalli
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul...Thanks a lot for the reply...Its working
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic