-->
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: Probleme with JPA out of container and Ejb3Configuration use
PostPosted: Fri Nov 10, 2006 8:55 pm 
Newbie

Joined: Mon Jun 20, 2005 11:38 am
Posts: 7
Hi,

I try for my test to use my entityManager out of container.

For that i instanciate my entityManagerFactory through the Ejb3Configuration helper.

All it's ok (annoted classes found, connection ok ...) but not my transactionType.

i try to add the property "javax.persistence.transactionType" ->"RESOURCE_LOCAL" without success

After inspection of sources it's seem this property is available through the configure() method who need the name of a file configuration.

But i don't want that a want define my entityManager only programaticly.

Is'it possible ?

Thank for your help ;)


Top
 Profile  
 
 Post subject: Crazy configuration ;)
PostPosted: Sat Nov 11, 2006 6:38 pm 
Newbie

Joined: Mon Jun 20, 2005 11:38 am
Posts: 7
Ok so after some investigations.

Code:
      Ejb3Configuration cfg = new Ejb3Configuration();
       cfg.addProperties(getProperties());
       cfg.addAnnotatedClass(User.class);
       entityManagerFactory = cfg.buildEntityManagerFactory();

    private static Properties getProperties() {
        Properties properties = new Properties();
        properties.setProperty(Environment.DRIVER, DATABASE_DRIVER_CLASS);
        properties.setProperty(Environment.URL, MEMORY_DATABASE_URL);
        properties.setProperty(Environment.USER, USERNAME);
        properties.setProperty(Environment.PASS, PASSWORD);
        properties.setProperty(Environment.DIALECT, DBDIALECT);
        properties.put(Environment.SHOW_SQL, "true");
        properties.put(Environment.FLUSH_BEFORE_COMPLETION, "false");
        properties.put(Environment.TRANSACTION_STRATEGY,   PersistenceUnitTransactionType.RESOURCE_LOCAL);
        properties.put(Environment.HBM2DDL_AUTO, "create");
        return properties;
    }


This code don't work because my entityManagerFactory doesn't have TransactionStrategy attached.

But if i use this code

Code:
Ejb3Configuration cfg = new Ejb3Configuration();
            cfg.addProperties(getProperties());
            cfg.addAnnotatedClass(User.class);
            cfg.configure("hibernate.cfg.xml");
            entityManagerFactory = cfg.buildEntityManagerFactory();


with a empty hibernate.cfg.xml config file like that ...

Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

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


the entityManagerFactory have a transaction manager attached !!!!

You can reply me hey guys all is ok good but not really. Because we can see the cfg.configure("hibernate.cfg.xml") don't use a resource or an input stream but a string. So the location of my file must be in my source directory but i dont want that. I want to use my file in my test directory tree.

So i've miss something or the Ejb3Configuration file have some issue ?

Thank's a lot for any informations on this point.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 13, 2006 6:38 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Environment.TRANSACTION_STRATEGY refers to the TransactionFactory implementation, this is not the property to define the JPA transaction-type

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Configuration again ;)
PostPosted: Mon Nov 13, 2006 8:43 pm 
Newbie

Joined: Mon Jun 20, 2005 11:38 am
Posts: 7
Hi emmanuel,

When i read your comment i understand that my code :

Code:
properties.put(Environment.TRANSACTION_STRATEGY,   PersistenceUnitTransactionType.RESOURCE_LOCAL);


is no good because PersistenceUnitTransactionType.RESOURCE_LOCAL is jpa transaction type and not hibernate !!!.

Which configuration information must be in place of PersistenceUnitTransactionType.RESOURCE_LOCAL ?

Why now it's working and why this propertiy is enabled if i give a empty config file ?


Another strange configuration issue in the class InjectionSettingsFactory.

When i used the static call to the method

Code:
protected ConnectionProvider createConnectionProvider(Properties properties) {
      return ConnectionProviderFactory.newConnectionProvider( properties, connectionProviderInjectionData );
   }


the code :

Code:
public static ConnectionProvider newConnectionProvider(Properties properties, Map connectionProviderInjectionData) throws HibernateException {
      ConnectionProvider connections;
      String providerClass = properties.getProperty(Environment.CONNECTION_PROVIDER);
      if ( providerClass!=null ) {
         try {
            log.info("Initializing connection provider: " + providerClass);
            connections = (ConnectionProvider) ReflectHelper.classForName(providerClass).newInstance();
         }
         catch (Exception e) {
            log.fatal("Could not instantiate connection provider", e);
            throw new HibernateException("Could not instantiate connection provider: " + providerClass);
         }
      }


alway thow and exception

Code:
java.lang.ClassCastException: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
   at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:73)


In debug mode the providerClass is by default an
org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider

who is a ConnectionProvider !!! this is totaly crazy when i evaluate the expression no error is thrown but when i step over error is reased !!!

I miss again something ?

Thank's


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 11:19 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I don't know about the CCE

For the first issue, configure() does trigger the default value initialization. Open a JIRa issue asking for the ability to get the default values wo calling configure().

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 12:19 pm 
Newbie

Joined: Mon Jun 20, 2005 11:38 am
Posts: 7
Hi Emmanuel thank's for your respons, i Open a Jira issue for the first issue.

For the second the issue is resolved. The error is when i try to configure JPA + Hibernate through Spring ;)

The option :

Code:
<property name="loadTimeWeaver">
            <bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver"/>
        </property>


As a impact on the classLoading ;( and generate two ClassCastException with hibernate.

One on the Ejb3Configuration.java line 407

Code:
try {
         saxReader.setFeature( "http://apache.org/xml/features/validation/schema", true );



And a another in ConnectionProviderFactory line 73

Code:
String providerClass = properties.getProperty(Environment.CONNECTION_PROVIDER);
      if ( providerClass!=null ) {
         try {
            log.info("Initializing connection provider: " + providerClass);
            connections = (ConnectionProvider) ReflectHelper.classForName(providerClass).newInstance();
         }
         catch (Exception e) {
            log.fatal("Could not instantiate connection provider", e);
            throw new HibernateException("Could not instantiate connection provider: " + providerClass);
         }
      }


So i need to remove this option and all is ok ;)

Thank's a lot Emmanuel for your patience.


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.