-->
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: No connection specified for the project.
PostPosted: Wed Sep 06, 2017 11:07 am 
Beginner
Beginner

Joined: Tue Aug 08, 2017 12:14 am
Posts: 44
Hi expert,

Can someone advise me how to resolve :

Quote:
No connection specified for the project.
No database-specific validation will be performed.


Basically, I have removed the persistence.xml file since I am using hibernate. Correct me if I am wrong. I do not need persistence.xml file anymore right ?

And then, I changed the connection to a singleton connection though I am abit stumped how to chain it to the hibernate utility....

Removed Eclipse-Link from my project.

Added in proxy-data source to the hibernate utility as follows :

Code:
package util;

import java.io.IOException;

import javax.sql.DataSource;

import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.jboss.logging.Logger;

import net.ttddyy.dsproxy.listener.logging.CommonsLogLevel;
import net.ttddyy.dsproxy.listener.logging.SLF4JLogLevel;
import net.ttddyy.dsproxy.support.ProxyDataSource;
import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder;

public class HibernateUtil {

   private static final SessionFactory sessionFactory;
      
   private static Logger log = Logger.getLogger(HibernateUtil.class);
   static {
      try {
         // Create the SessionFactory from hibernate.cfg.xml
         Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
         log.info("Hibernate Configuration loaded");
         configuration.addAnnotatedClass(model.Tutor.class);
         configuration.addAnnotatedClass(model.Subject.class);
         StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
               .applySettings(configuration.getProperties());
         sessionFactory = configuration.buildSessionFactory(builder.build());
         // sessionFactory = new
         // Configuration().configure().buildSessionFactory();
         log.info("sessionFactory created.");
      } catch (Throwable ex) {
         // Make sure you log the exception, as it might be swallowed
         System.err.println("Initial SessionFactory creation failed." + ex);
         throw new ExceptionInInitializerError(ex);
      }
   }

   public static SessionFactory getSessionFactory() {
      return sessionFactory;
   }
   
   public static ProxyDataSource getDataSource() {
      return newDataSource();
   }

   private static ProxyDataSource newDataSource() {
   DataSource ds = null;
   ds=SingletonDBConnection.getMySQLDataSource();
   ProxyDataSource proxyDataSource = new ProxyDataSource();
   proxyDataSource.setDataSource(ds);ProxyDataSourceBuilder.create(ds).logQueryByCommons(CommonsLogLevel.INFO).logQueryBySlf4j(SLF4JLogLevel.INFO)
   .build();
   // proxyDataSource.setListener(new SLF4JQueryLoggingListener());
   try
   {
      proxyDataSource.close();
   }catch(
   IOException e)
   {
      // TODO Auto-generated catch block
      e.printStackTrace();
   }
return proxyDataSource;
}}
// proxyDataSource.ew SLF4JQueryLoggingListener());
// return proxyDataSource;






The hibernate.cfg.xml contains the jdbc connection details.

So, I do not know why I got the above error.

Hope someone can let me know the reason.

Tks.


Top
 Profile  
 
 Post subject: Re: No connection specified for the project.
PostPosted: Wed Sep 06, 2017 11:16 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Quote:
Correct me if I am wrong. I do not need persistence.xml file anymore right ?


You don't need it if you are using the Hibernate-specific bootstrap.

Quote:
And then, I changed the connection to a singleton connection though I am abit stumped how to chain it to the hibernate utility....


I see that you want to create a ProxyDataSource, but did you provide that to Hibernate?

You could pass a custom DataSource to Hibernate via the hibernate.connection.datasource configuration property which can take:

- a JNDI string
- a DataSource object reference

However, you need to switch to the new boostrap API since this one, based on Configuration object, will be deprecated soon. Check out this GitHub test case for more details about how to do that.


Top
 Profile  
 
 Post subject: Re: No connection specified for the project.
PostPosted: Sun Sep 17, 2017 11:27 pm 
Beginner
Beginner

Joined: Tue Aug 08, 2017 12:14 am
Posts: 44
vlad wrote:
Quote:
Correct me if I am wrong. I do not need persistence.xml file anymore right ?


You don't need it if you are using the Hibernate-specific bootstrap.

Quote:
And then, I changed the connection to a singleton connection though I am abit stumped how to chain it to the hibernate utility....


I see that you want to create a ProxyDataSource, but did you provide that to Hibernate?

You could pass a custom DataSource to Hibernate via the hibernate.connection.datasource configuration property which can take:

- a JNDI string
- a DataSource object reference

However, you need to switch to the new boostrap API since this one, based on Configuration object, will be deprecated soon. Check out this GitHub test case for more details about how to do that.


Hi,

I got the below error but I am not sure what's happening regarding the connection portion.

Code:
2017-09-18 11:15:58,996 http-nio-8013-exec-6 ERROR Null object returned for Jdbc in appenders.
2017-09-18 11:15:59,000 http-nio-8013-exec-6 ERROR No ConnectionSource provided: connectionSource
2017-09-18 11:15:59,003 http-nio-8013-exec-6 ERROR Unable to inject fields into builder class for plugin type class org.apache.logging.log4j.core.appender.db.jdbc.JdbcAppender, element Jdbc. org.apache.logging.log4j.core.config.ConfigurationException: Arguments given for element Jdbc are invalid
   at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.injectFields(PluginBuilder.java:198)
   at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:121)



Code:
2017-09-18 11:15:59,014 http-nio-8013-exec-6 ERROR Null object returned for Jdbc in appenders.
2017-09-18 11:15:59,071 http-nio-8013-exec-6 ERROR Unknown object "Logger" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored: try nesting it inside one of: ["Appenders", "Loggers", "Properties", "Scripts", "CustomLevels"].
2017-09-18 11:15:59,102 http-nio-8013-exec-6 ERROR Unknown object "Logger" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored: try nesting it inside one of: ["Appenders", "Loggers", "Properties", "Scripts", "CustomLevels"].
2017-09-18 11:15:59,104 http-nio-8013-exec-6 ERROR Unknown object "logger" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored: try nesting it inside one of: ["Appenders", "Loggers", "Properties", "Scripts", "CustomLevels"].
2017-09-18 11:15:59,108 http-nio-8013-exec-6 ERROR Unknown object "logger" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored: try nesting it inside one of: ["Appenders", "Loggers", "Properties", "Scripts", "CustomLevels"].
2017-09-18 11:15:59,111 http-nio-8013-exec-6 ERROR Unknown object "Root" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored: try nesting it inside one of: ["Appenders", "Loggers", "Properties", "Scripts", "CustomLevels"].
2017-09-18 11:15:59,113 http-nio-8013-exec-6 ERROR Unable to locate appender "databaseAppender" for logger config "root"
Initial SessionFactory creation failed.org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Sep 18, 2017 11:16:02 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [tutorController] in context with path [/Hi5S] threw exception [Servlet execution threw an exception] with root cause
javax.naming.NameNotFoundException: Name [hi5"/>] is not bound in this Context. Unable to find [hi5"].
   at org.apache.naming.NamingContext.lookup(NamingContext.java:818)
   at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
   at org.apache.naming.NamingContext.lookup(NamingContext.java:829)
   at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
   at org.apache.naming.NamingContext.lookup(NamingContext.java:829)
   at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
   at org.apache.naming.NamingContext.lookup(NamingContext.java:829)
   at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
   at org.apache.naming.SelectorContext.lookup(SelectorContext.java:134)
   at javax.naming.InitialContext.lookup(InitialContext.java:421)
   at org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:97)
   at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:98)


I have included the below inside hibernate.cfg.xml and removed all the username, password as one of the advice given in stackoverflow.
Code:
      <!-- Connection Pool Size (built-in) -->

      <property name="connection.pool.size">1</property>

            
         <!-- SQL Dialect -->

         <property name="dialect">org.hibernate.dialect.MySQLMyISAMDialect</property>


For now, I am using the JPA that comes with 'J2ee framework'.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="Hi5S" transaction-type="JTA" >   
    <class>model.Subject</class>
      <class>model.Tutor</class>
   
     <properties>
     <!-- Configuring JDBC properties --> 
              <property name="hibernate.connection.datasource" value="java:comp/env/jdbc/hi5"/> 
     
   </properties>         
   </persistence-unit>
   
</persistence>


Am not able to figure out what's wrong after doing all the 'necessary' and not sure what's amiss.

Hope to have some advice. tks.


Top
 Profile  
 
 Post subject: Re: No connection specified for the project.
PostPosted: Mon Sep 18, 2017 1:49 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Quote:
SEVERE: Servlet.service() for servlet [tutorController] in context with path [/Hi5S] threw exception [Servlet execution threw an exception] with root cause
javax.naming.NameNotFoundException: Name [hi5"/>] is not bound in this Context. Unable to find [hi5"].


The message is very clear about the issue: the JNDI resource cannot be resolved.


Top
 Profile  
 
 Post subject: Re: No connection specified for the project.
PostPosted: Mon Sep 18, 2017 11:47 pm 
Beginner
Beginner

Joined: Tue Aug 08, 2017 12:14 am
Posts: 44
vlad wrote:
Quote:
SEVERE: Servlet.service() for servlet [tutorController] in context with path [/Hi5S] threw exception [Servlet execution threw an exception] with root cause
javax.naming.NameNotFoundException: Name [hi5"/>] is not bound in this Context. Unable to find [hi5"].


The message is very clear about the issue: the JNDI resource cannot be resolved.


Hi vlad,

Thanks for your reply.

Can I know is it that I have to implements ServletContextListener in order for this connection to work ?


Top
 Profile  
 
 Post subject: Re: No connection specified for the project.
PostPosted: Tue Sep 19, 2017 1:23 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
It's better to check the application server documentation for more details of how to setup and resolve JNDI resources.


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.