Cannot find Persistence provider from persistence.xml [duplicate] - spring-mvc

This question already has answers here:
No Persistence provider for EntityManager named
(32 answers)
Closed 4 years ago.
When I run my project, it threw exeption like this:
Request processing failed; nested exception is javax.persistence.PersistenceException: No Persistence provider for EntityManager named "LessonJPAPU"
My persistence.xml is like this:
<persistence-unit name="LessonJPAPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.javatpoint.beans.Emp</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/users"/>
<property name="javax.persistence.jdbc.user" value="postgres"/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="javax.persistence.jdbc.password" value=""/>
</properties>
</persistence-unit>
What's wrong?

Make sure that your persistence.xml is in src/main/resources/META-INF folder and that folder is not excluded form classpath.

Related

Upgrade of Spring webflow 1.0 to 2.4.2 - Setting default flow id?

I'm very much new to spring webflow framework and I have been working on upgrading the existing project on spring webflow 1.0 to use spring webflow 2.4.2 latest framework. Currently on our project we are using the defaultFlowId in dispatcher-servlet.xml and there is a corresponding setter method at FlowController.java of spring webflow 1.0 but it is not available with the current webflow framework.
I would like to understand if there is any alternative for the same ?
(dispatcher-servlet.xml)
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/**/index.htm=loginController
</value>
</property>
</bean>
<bean name="loginController" class="com.example.ui.controllers.LoginController">
<property name="defaultFlowId" value="init-flow" />
<property name="flowExecutor" ref="flowExecutor" />
</bean>
Now it says, Caused By: org.springframework.beans.NotWritablePropertyException: Invalid property 'defaultFlowId' of bean class [com.example.ui.controllers.LoginController]: Bean property 'defaultFlowId' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Since there is no setDefaultFlowId() in latest FlowController.java of org.springframework.webflow.mvc.servlet.FlowController
Anyone who worked/used the above method ? or can i know whether we can define the same kind of defaultId in other ways ?
Any help would be greatly appreciated !
We have upgraded. Here is the flow definition that we are required to use in order that the flow is maintained and default flow is used:
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/**/index.htm=yourController
</value>
</property>
</bean>
And the rest:
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location id="index" path="/WEB-INF/initialflow.xml" />
</webflow:flow-registry>

using c3p0 with java MVC (JDK 1.6)

I'm trying to create global connections for multiple WAR files (apps) to use.
Each project use entity manager architecture and maven. I'm using spring 3.5.1, tomcat 6.0.39, JDK 1.6.0_45, C3P0 0.9.1.2, hibernate-c3p0 4.2.3.Final, com.mchange c3p0 0.9.2
I saw examples all over but none works for me, I'm not sure why.
I tried almost everything, but I have no clue what's wrong.
I've written into server.xml the following:
<Resource auth="Container"
description="DB Connection"
driverClass="com.mysql.jdbc.Driver"
maxPoolSize="20"
minPoolSize="12"
acquireIncrement="1"
name="jdbc/testdb1"
user="root"
password=""
factory="org.apache.naming.factory.BeanFactory"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
jdbcUrl="jdbc:mysql://localhost:3306/test_db1?autoReconnect=true" />
and into context.xml the following:
<ResourceLink name="jdbc/testdb1"
global="jdbc/testdb1"
type="javax.sql.DataSource" />
and into web.xml the following:
<resource-ref>
<res-ref-name>jdbc/testdb1</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
and my project (app) specific configuration:
PART 1 (JPA XML FILE):
<bean id="transactionManagerMysql" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="emfMysql"/>
</bean>
<bean id="emfMysql" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="jdbc/testdb1" />
<property name="persistenceXmlLocation" value="classpath:persistence-infrastructure.xml" />
<property name="persistenceUnitName" value="puMysql" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.jdbc.fetch_size">50</prop>
<prop key="hibernate.jdbc.batch_size">10</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<jpa:repositories base-package="domain.data.repository"
entity-manager-factory-ref="emfMysql"
transaction-manager-ref="transactionManagerMysql"/>
PART 2 (PERSISTENCE XML FILE):
<persistence-unit name="puMysql" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>domain.Mysqltable1</class>
<properties>
<property name="hibernate.connection.datasource" value="jdbc/testdb1"/>
</properties>
</persistence-unit>
I get an exception:
Error creating bean with name 'emfMysql' defined in class path resource [datasource-tx-jpa-infrastructure.xml]: Cannot resolve reference to bean 'jdbc/testdb1' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'jdbc/testdb1' is defined
I hope someone can help me :)
Thanks ahead
It said that the datasource resource you defined in tomcat server.xml is not a bean in spring. You should define a datasource bean like this:
<bean id="dbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/DatabaseName"/>
</bean>
And use this bean instead of jndi name for datasource property of emfMysql.
Please refer this answer

Issue loading application context running Junit4 and Spring

I am playing with writing integration tests for our project. This is the first time I am writing tests so please pardon me if this is a simple question.
I have different modules like core, site, admin etc.,
I want to keep our unit tests separate from our integration tests. So in the core of the project, I created a folder src/it/java and a package in it - com.test.integration. This package has the test that I am trying to run.
The test application context and required test properties files are in src/it/java directly. I added src/it/java to my build path. In my application context I have the following
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="url" value="jdbc:mysql://${mysql.host}/${mysql.db_blc}?autoReconnect=true&useUnicode=true&characterEncoding=UTF8"/>
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="username" value="${mysql.user}" />
<property name="password" value="${mysql.pass}" />
<property name="testWhileIdle" value="true"/>
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="false"/>
<property name="validationQuery" value="SELECT 1"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
<constructor-arg ref="dataSource" />
</bean>
Now in my sample test
#RunWith(BlockJUnit4ClassRunner.class)
#ContextConfiguration("/applicationContext-test.xml")
public class SampleTest {
#Resource(name="jdbcTemplate")
private NamedParameterJdbcTemplate jdbcTemplate;
}
The jdbcTemplate bean is null and I can't seem to figure out why.
Any input is appreciated. We are using Spring 3.0.5 and JUnit4
Thanks
Mehul
try using SpringJunit4ClassRunner
I would suggest changing the context configuration to this
#ContextConfiguration("classpath:/applicationContext-test.xml")

Configure an External LDAP User Store with WSO2 Identity Server

My Current configuration is
#
<UserManager>
<Realm>
<Configuration>
<AdminRole>admin</AdminRole>
<AdminUser>
<UserName>admin</UserName>
<Password>XXXXXX</Password>
</AdminUser>
<EveryOneRoleName>everyone</EveryOneRoleName> <!-- By default users in thsi role sees the registry root -->
<!-- <ReadOnly>false</ReadOnly> -->
<MaxUserNameListLength>500</MaxUserNameListLength>
<Property name="url">jdbc:h2:repository/database/WSO2CARBON_DB</Property>
<Property name="userName">wso2carbon</Property>
<Property name="password">wso2carbon</Property>
<Property name="driverName">org.h2.Driver</Property>
<Property name="maxActive">50</Property>
<Property name="maxWait">60000</Property>
<Property name="minIdle">5</Property>
</Configuration>
<UserStoreManager
class="org.wso2.carbon.user.core.ldap.LDAPUserStoreManager">
<Property name="ConnectionURL">ldap://localhost:389</Property>
<Property name="ConnectionName">cn=admin,dc=ysd,dc=com</Property>
<Property name="ConnectionPassword">admin32</Property>
<Property name="UserSearchBase">ou=People,dc=ysd,dc=com</Property>
<Property name="UserNameListFilter">(objectClass=person)</Property>
<Property name="UserNameAttribute">uid</Property>
<Property name="ReadLDAPGroups">false</Property>
<Property name="GroupSearchBase">ou=People,dc=ysd,dc=com</Property>
<Property name="GroupSearchFilter">(objectClass=groupOfNames)</Property>
<Property name="GroupNameAttribute">cn</Property>
<Property name="MembershipAttribute">member</Property>
</UserStoreManager>
<AuthorizationManager
class="org.wso2.carbon.user.core.authorization.JDBCAuthorizationManager">
</AuthorizationManager>
</Realm>
</UserManager>`
#
Iam geeting following error while starting server.
*ERROR {org.wso2.carbon.user.core.common.DefaultRealm} - Cannot create org.wso2.carbon.user.core.ldap.LDAPUserStoreManager . Error is : null
java.lang.reflect.InvocationTargetException*
..............
............
............
Caused by: org.wso2.carbon.user.core.UserStoreException: LDAPUserStoreManager is unable to operate in Read-Write mode. This is invalid configuration. It can only operate in ReadOnly mode
at org.wso2.carbon.user.core.ldap.LDAPUserStoreManager.(LDAPUserStoreManager.java:97)
... 25 more
What is your exact requirement ? Do you want the Identity Server to do Read-Write operation on the external LDAP or do you want to do only the Read operations ?
You get this exception because you are trying to use the read only ldap user store for both read-write operations. Set the parameter <ReadOnly>false</ReadOnly>to true, then this error would go away.
But if your requirement is to use IS for both read write operations use the ApacheDSUserStoreManager. You can use the LDAPUserStoreManager for that.

Nhibernate Session and ASP.NET

Using NhibernateProfiler we have determined that we are creating an ISession for every http request. However the ISessions never close. We can see in the log where localSession.Close() fires. Is there something in our config file that would cause the session to never close? Are there any other reasons localSession.Close() would not physical close the session? We are on 2.1 of NHibernate.
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">JCDCHelper.DAL.Utilities.JCDCConnectionProvider, JCDCHelper.DAL</property>
<property name="dialect">NHibernate.Dialect.Sybase</property>
<property name="connection.release_mode">on_close</property>
<property name="show_sql">true</property>
<property name="connection.driver_class">JCDCHelper.DAL.Utilities.DataDirectSybaseDriver, JCDCHelper.DAL</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="connection.connection_string_name">ProdSybase</property>
<property name="current_session_context_class">web</property>
</session-factory>
</hibernate-configuration>
Thanks for taking the time to read this.
Are you Disposing the ISession? Wrapping it in a using statement?

Resources