Persistence 1.0/2.0 XSD is down? - spring

I've created a spring project which I later deployed on glassfish, the ap is working at first. But when I added persistence.xml it took mins to be done with error.
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
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">
<persistence-unit name="sidoPU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>myDatasource</jta-data-source>
<properties>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.SunONETransactionManagerLookup" />
<property name="hibernate.transaction.factory_class"
value="org.hibernate.transaction.JTATransactionFactory" />
</properties>
</persistence-unit>
</persistence>
When browse: http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd, it wouldn't load.
Any idea or work around on this issue?

I think it's related with the whole java.net, java.sun.com, project Kenai etc. being down because of the maintenance reasons.
https://blogs.oracle.com/theaquarium/entry/outage_on_java_net_apr

Related

Setting JDBC connection/socket timeout via persistence.xml

I'm trying to set JDBC timeout via persistence.xml, but it doesn't work.
This is how my persistence.xml looks like:
<persistence-unit name="persistenceUnit" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>OracleDataSourceExample</jta-data-source>
<properties>
<property name="oracle.net.READ_TIMEOUT" value="1"/>
<property name="oracle.jdbc.ReadTimeout" value="1"/>
<property name="oracle.net.CONNECT_TIMEOUT" value="1"/>
</properties>
</persistence-unit>
So, does anyone have suggestion what to do? (how to set jdbc timeout)

why database is empty after login

I am developing j2EE application it is web sotre I use Jboss7 , maven and wildfly my problem is that after every login database content will be deleted .. any suggestion to solve this ?
this is my persistance file
<?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="PiDevECommerce-ejb">
<jta-data-source>java:jboss/datasources/MySQLDS</jta-data-source>
<class>ecommerce.entites.Admin</class>
<class>ecommerce.entites.Brand</class>
<class>ecommerce.entites.Category</class>
<class>ecommerce.entites.Coupon</class>
<class>ecommerce.entites.Customer</class>
<class>ecommerce.entites.Event</class>
<class>ecommerce.entites.Offre</class>
<class>ecommerce.entites.Product</class>
<class>ecommerce.entites.Publication</class>
<class>ecommerce.entites.ReclamationCoupon</class>
<class>ecommerce.entites.ReclamationOffre</class>
<class>ecommerce.entites.Review</class>
<class>ecommerce.entites.Store</class>
<class>ecommerce.entites.Storemanager</class>
<class>ecommerce.entites.Transaction</class>
<class>ecommerce.entites.TransactionPK</class>
<class>ecommerce.entites.User</class>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
</persistence>
The problem is in your configuration
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
The correct value would be validate
This post answer your question completely
Click here

JPA Hibernate working very slow

I am learning JPA.
I tried the Spring-JPA-Hibernate combination.
The application works and I get the results.
But though there is only 1 record in the database, it is taking about 4 to 5 minutes to load the page.
Not quite sure what I am doing wrong.
I Googled for the same but all I am getting are performance optimization suggestions but I think I am missing something more basic as there is only 1 record in my table.
Here are the details:
Persistence.xml
<?xml version="1.0" encoding="UTF-8" ?>
<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" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="bike_unit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:comp/env/jdbc/testdb123</jta-data-source>
<class>bike.Bike</class>
<class>bike.Company</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/bike"/>
<property name="javax.persistence.jdbc.user" value="abc"/>
<property name="javax.persistence.jdbc.password" value="abc"/>
</properties>
</persistence-unit>
</persistence>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>bikeDispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>bikeDispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/home.html</welcome-file>
</welcome-file-list>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<resource-env-ref>
<resource-env-ref-name>jdbc/testdb123</resource-env-ref-name>
<resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
</resource-env-ref>
</web-app>
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/testdb123" auth="Container"
type="javax.sql.DataSource"
username="abc" password="abc"
driverClassName="org.apache.derby.jdbc.ClientDriver"
url="jdbc:derby://localhost:1527/bike" />
</Context>
I am using Spring 3 and Hibernate 3 jar files.
I tried replacing Hibernate with Eclipselink and the applications works perfect. Its only when I use JPA with Hibernate that I have slowness issues.
Here are the jars I used with Eclipselink and Hibernate:
Eclipselink:
eclipselink.jar
javax.persistence_2.1.0.v201304241213.jar
javax.persistence.source_2.1.0.v201304241213.jar
Hibernate:
ejb3-persistence.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
With Eclipselink, this is how my persistance.xml looks:
<?xml version="1.0" encoding="UTF-8" ?>
<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" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="bike_unit" transaction-type="RESOURCE_LOCAL">
<class>bike.Bike</class>
<class>bike.Company</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/bike" />
<property name="javax.persistence.jdbc.user" value="abc" />
<property name="javax.persistence.jdbc.password" value="abc" />
</properties>
</persistence-unit>
</persistence>
Not sure what I am missing.
I had this performance problem on Windows 7 Desktop.
However, I did not face this issue when tried on a Windows 8 Machine with identical code and database.
Did not find the root cause but solved my problem for now.

Separate DB just for JUnit tests in Spring app

I am writing unit tests for my Spring application using in-file HSQL db. I don't want to pollute this db with test data, so I am trying to set up another in-memory HSQL db instance to be used in tests.
In my abstract testing class I import test application context XML configuration:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration("/testingContext.xml")
#Transactional
public abstract class AbstractDaoForTesting {
testingContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
">
<jdbc:embedded-database id="dataSource" type="HSQL" />
<bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.se.micom" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="myEmf" />
</bean>
<tx:annotation-driven />
<bean id="persistenceExceptionTranslationPostProcessor" class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<bean id="characteristicDao" class="com.se.micom.dao.CharacteristicDaoImpl"/>
<bean id="functionalityDao" class="com.se.micom.dao.FunctionalityDaoImpl"/>
<bean id="segmentDao" class="com.se.micom.dao.SegmentDaoImpl"/>
<bean id="segmentService" class="com.se.micom.service.SegmentServiceImpl"/>
<bean id="functionalityService" class="com.se.micom.service.FunctionalityServiceImpl"/>
<bean id="characteristicService" class="com.se.micom.service.CharacteristicServiceImpl" />
</beans>
Up to now in-memory HSQL db is working fine in test.
However, as soon as I introduce in my project persistence.xml in src/main/resources/META-INF unit tests start to use this persistence unit and not the one from testingContext.xml.
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
<persistence-unit name="micomPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.se.micom.dao.domain.Characteristic</class>
<class>com.se.micom.dao.domain.Functionality</class>
<class>com.se.micom.dao.domain.Segment</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:file:D:\workspace_java\Micom2\db\micom"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver"/>
<property name="javax.persistence.jdbc.user" value="sa"/>
</properties>
</persistence-unit>
</persistence>
What's wrong with this configuration? Why tests "prefer" to use db defined in persistence.xml?
Your problem is a perfect example for Spring profiles. It is always problematic to have multiple beans doing the same thing in your context at once if you want a certain one to be used.
You should have two different profiles, "prod" and "test", and wrap your bean declaration in the xml config accordingly with <beans profile="XYZ"> ... </beans>. A more extensive example can be found here.
You can then annotate your test with #Profile("test") and it should use the correct database.

Spring jpa(Hibernate) with tomcat

I'm working with JPA(Hibernate) and spring project these days, I configured spring, jpa and try to deploy the application on tomcat7, As I know jpa/hibernate creates tables using entity class first loading, but here I couldn't see any connection between database and application when applications starts, below you can see my configuration,I have seen lot of questions posted regarding this matter, I couldn't find the proper solution to my problem.
Can any one tell me what is the problem here.I have created a application without any issues in jetty server sometime back,
Thank you in advance
applicationContext-dao.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
default-lazy-init="true">
<!-- Use #Transaction annotations for managing transactions -->
<!--<tx:annotation-driven/>-->
<!-- holding properties for database connectivity / -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<tx:annotation-driven proxy-target-class="true" />
<!-- Activates scanning of #Autowired -->
<context:annotation-config/>
<!-- Activates scanning of #Repository -->
<context:component-scan base-package="lk.gov.elg"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}"/>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory"
p:dataSource-ref="dataSource"/>
<bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="dataSource"
p:jpaVendorAdapter-ref="jpaAdapter">
<property name="persistenceUnitName" value="eLGPersistenceUnit"></property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver"/>
</property>
</bean>
<!-- Jpa adapter for the Hibernate -->
<bean id="jpaAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
p:databasePlatform="org.hibernate.dialect.MySQLDialect"
p:generateDdl="true"
p:showSql="true" >
</bean>
<bean
class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/>
<bean
class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
</beans>
persistance.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
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">
<persistence-unit name="eLGPersistenceUnit"
transaction-type="RESOURCE_LOCAL">
<!--transaction-type="JTA">-->
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.hbm2ddl.auto" value="validate"/>
</properties>
<!--<provider>org.hibernate.ejb.HibernatePersistence</provider>-->
</persistence-unit>
</persistence>
I think there is no issue with your configuration, try after removing "default-lazy-init=true" attribute
Cheers
try changing:
<property name="hibernate.hbm2ddl.auto" value="validate"/>
to:
<property name="hibernate.hbm2ddl.auto" value="update"/>
or:
<property name="hibernate.hbm2ddl.auto" value="create"/>

Resources