I am following this link to generate hibernate file
https://www.mkyong.com/hibernate/how-to-generate-code-with-hibernate-tools/
the files are generated but without annotation.
I checked the "generate EJB3 annotation " but still it is not working
the DB is Postgres.
I use to do it the same way and it was working fine..
few weeks ago I upgrade to eclipse to oxygen and change my workplace
since then it is not working..
does any body know if there is a log file for the activity ? maybe I can find some thing there ?
this is my hibernate.cfg.xml file
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.url">jdbc:postgresql://xxxxx/yyy</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<!-- <property name="hibernate.enable_lazy_load_no_trans">false</property> -->
<property name="hibernate.search.autoregister_listeners">true</property>
<property name="hibernate.validator.apply_to_ddl">false</property>
<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
<property name="hibernate.enable_lazy_load_no_trans">true</property>
</session-factory>
After spending two days on it , I found the problem..
my hibernate version is 5.3 and still after changing the hibernate version to 5.2 (in the hibernate configuration window ) - it worked !!
After changing different possibilities in the configuration and connection, I changed the hibernate version from 5.3 to 5.2 and it works now ! (Tested on Photon and Oxygen versions of Eclipse)
In my case I have to check the checkboxe "Generate EJB3 annotations" with hibernate version 5.2 to make it work fine !
Related
I am using eclipseLink 2.5.2 JPA library with weblogic 12.2.1.4.0
I want to view all the sql queries executed by JPA in the weblogic console. I have done the below changes to my persistence.xml and enabled (Redirect stdout logging enabled and Redirect stderr logging enabled):
<property name="eclipselink.logging.file" value="output.log"/>
<property name="eclipselink.logging.logger" value="ServerLogger"/>
<property name="eclipselink.weaving" value="static" />
<property name="eclipselink.logging.level.sql" value="FINEST" />
<property name="eclipselink.logging.level" value="FINEST" />
<property name="eclipselink.logging.level.cache" value="FINEST" />
<property name="openjpa.Log" value="SQL=TRACE"/>
Still i am not able to view the generated sql in my weblogic console. Please let me know if i have missed any configuration.
Your configuration is telling EclipseLink that the server controls all logging when you specified <property name="eclipselink.logging.logger" value="ServerLogger"/>. This means everything is controlled through the WebLogic logging settings, not EclipseLink, and probably why you don't see anything. You will need to check the WebLogic docs on how to make changes within its console.
Otherwise, as per the EclipseLink documentation, you can specify <property name="eclipselink.logging.logger" value="DefaultLogger"/> to have it use the other EclipseLink property values you've defined and have them logged to the console.
Technologies: JSF, Hibernate 3, eclipse. Glassfish server
My website works 100% locally but when I deployed it, it just closes the connection after a while.
I thought of using a connection pool to avoid this issue
I downloaded the jar file c3p0-0.9.2.1.jar and added it in java class path an added the following configs in hibernate.cfg.xml and hibernate-c3p0-4.3.10.Final.jar
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
and it gives an error that a class named LogM is not found. might the jar file I used be a wrong one? or did I miss a step?
Caused by: java.lang.ClassNotFoundException: com.mchange.v2.log.MLog
My application was running properly when I was configuring Hibernate.cfg.xml without any DataSource.
I am deploying my application on Weblogic.
But now I have configured it using a Data Source, (both in .cfg as well as Weblogic).
Aster this suddenly I have started getting the exception when update on some table is happening. Without the DataSource its working fine.
This was the old config: (works fine)
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:#localhost:1521:XE</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="org.hibernate.envers.track_entities_changed_in_revision">true</property>
Following is the new config: (throws exception)
<property name="connection.datasource">DataSourceTest</property>
<property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="org.hibernate.envers.track_entities_changed_in_revision">true</property>
<property name="show_sql">true</property>
<!-- <property name="hibernate.connection.autocommit">true</property> -->
<property name="hibernate.hbm2ddl.auto">update</property>
I have made the similar cofiguration in Weblogic 12.1.3 also
But now its giving the following exception:
2016-07-20 14:45:02 INFO AbstractBatchImpl:208 - HHH000010: On release of batch it still contained JDBC statements
2016-07-20 14:45:02 WARN SqlExceptionHelper:144 - SQL Error: 17004, SQLState: 99999
2016-07-20 14:45:02 ERROR SqlExceptionHelper:146 - Invalid column type: 16
org.hibernate.exception.GenericJDBCException: could not update
All the Select and Insert queries are working just fine, but when the update happens, the above error is thrown.
My Lib folder contains the Hibernate Jar, JPA 2.1 jar.
Is it some issue with the configuration I am doing?
All my mappings and columns etc seems to be fine.
Any help would be appreciated.
Hello the problem is coming from the fact that support of boolean in Oracle is either CHAR(1) or alternatively NUMBER(1). Which basically means that you will either have '1'-'0' or 'Y' -'N' combinations respectively. The problem is a conversion problem the JDBC driver needs to know how to convert your boolean into the CHAR(1)/NUMBER(1)
You can try the following:
1. Set your dialect to org.hibernate.dialect.Oracle10gDialect
Alternatively you can try to convert the Number(1)/Char(1):
#org.hibernate.annotations.Type(type="true_false")
#NotNull
boolean value;
or
#org.hibernate.annotations.Type(type="yes_no")
#NotNull
boolean value;
I am learning hibernate. I downloaded the hibernate-release 5.0.1 Final and copied all the jars in the required and java8 folders into my project. I am using java8 jdk in my system.
I am trying to execute a very basic program:
public class HibernateTest {
public static void main(String[] args){
UserDetails user = new UserDetails();
user.setUserId(1);
user.setUserName("First User");
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
session.save(user);
session.getTransaction().commit();
session.close();
}
}
The hibernate configuration file is also very basic:
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://localhost:5432/Training</property>
<property name="connection.username">postgres</property>
<property name="connection.password">password</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<mapping class="org.vicky.dto.UserDetails"/>
</session-factory>
</hibernate-configuration>
The result is:
Exception in thread "main" java.util.ServiceConfigurationError: org.hibernate.boot.model.TypeContributor: Provider org.hibernate.type.Java8DateTimeTypeContributor not found
at java.util.ServiceLoader.fail(ServiceLoader.java:231)
at java.util.ServiceLoader.access$300(ServiceLoader.java:181)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:365)
at java.util.ServiceLoader$1.next(ServiceLoader.java:445)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:324)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:356)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at org.vicky.hibernate.HibernateTest.main(HibernateTest.java:19)
Please help me out. I searched in that package for this missing class file. But it is not there. Thank you for your answers.
Remove java8 jar file from build path libraries.
You are missing the hibernate-java8 jar in your class path. You can find it here.
I got it fixed just now. I have installed multiple eclipse IDEs in my system. Found out that the one I am using with this project is using JDK 1.7. I have changed it to JDK 1.8 and everything got smooth now (Windows->preferences->java->installed JREs->Add and point to JDK 1.8 directory).
But can someone explain how eclipse works here?
I have installed Java 8 RE in my system. May be that's why this particular eclipse is expecting Java 8 related classes but without detecting them even though they are added to the project, because it's "installed JREs" setting is pointing to JDK 1.7 . No clue what exactly is happening here with eclipse.
Thank you for your answers subodh and danizmax. Nice evening!
I'm migrating an application packaged as a HAR hibernate archive from JBoss AS5 to AS7. I have a number of questions, and I know I have a number of hurdles I have to face in order to migrate my application successfully. I don't mind researching things on my own - but at this point I'm not quite sure what is possible, or the direction I should take and would appreciate any pointers or comments.
I know that JBoss AS7 does not support HAR hibernate archives - so I have to make some sort of changes in order to get this to work. My app requires hibernate3, which I include as a dependency. My HAR is structured like
HAR
|
|-com
| |-business classes
| |-*class files and *hbm.xml files
|
|-META-INF
|-hibernate.xml
My hibernate.xml file looks like
<hibernate-configuration xmlns="urn:jboss:hibernate-deployer:1.0">
<session-factory name="java:/hibernate/SessionFactory" bean="jboss.har:service=Hibernate">
<property name="datasourceName">java:/MySqlDS</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- <property name="sessionFactoryInterceptor">org.jboss.test.hibernate.SimpleInterceptor</property> -->
<!-- <property name="hbm2ddlAuto">create</property> -->
<depends>jboss:service=Naming</depends>
<depends>jboss:service=TransactionManager</depends>
</session-factory>
</hibernate-configuration>
We are using *hbm.xml files in our HAR to define entities, and not the newer style of hibernate annotations. A couple of questions I have are:
-is there a way I can just package my HAR as a JAR and use it inside of AS7 without having to go through the trouble of rewrite my business classes to use annotations to define entities instead of using *hbm.xml files?
-if not is there a guide somewhere about converting your code to use hibernate annotations and persistence.xml? I don't mind doing research but right now I'm not sure what I should be researching.
HAR archives do not exist in JBoss 7 anymore. In fact even the ServiceMBeanSupport does not exist anymore. One possibility is to use some mechanism to create the SessionFactory and inject it into the JNDI. Another possibility is to “use and not use” the new JPA api. By “use” I mean define Hibernate configuration in a persistence.xml file and use the mapping detection feature available. This would allow the plain renaming of the .har to a .jar with an added META-INF/persistence.xml file without the need to hardcode all the mappings and classes in a long list somewhere. By “not use” I mean to have the JPA initialized but use the old SessionFactory instead because there is no reason to change to the new API when the old one works quite well.
However, another problem is that JBoss 7 is bundled with Hibernate 4 and the migration might not be straightforward. However there is still a possibility to bundle a Hibernate as lower as 3.5 in your application. Here is the persistence.xml:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="X">
<description>X</description>
<jta-data-source>java:/XOracleDS</jta-data-source>
<properties>
<!-- This tells JBoss to use Hibernate 3 (as low as 3.5) bundled into the application -->
<property name="jboss.as.jpa.providerModule" value="hibernate3-bundled" />
<!--<property name="jboss.as.jpa.managed" value="false"/>-->
<!-- This will bind the session factory to JNDI as we require -->
<property name="hibernate.session_factory_name" value="java:/hibernate/XOracleSessionFactory"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
<!-- This is one of the trickiest parts as Hibernate 3.5 does not has a RegionFactory and we must use the one from ehcache to bridge the gap -->
<property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.EhCacheRegionFactory"/>
<!-- very important to allow same names as in JBoss 4 -->
<property name="hibernate.cache.region_prefix" value=""/>
<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"/>
<!-- This will make use of JBoss managed transactions. The factory is already present in JNDI -->
<property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/>
<property name="hibernate.jdbc.batch_size" value="20"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="false"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
</properties>
</persistence-unit>
</persistence>