Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPA Partitioning and Spring
JPA Partitioning and Spring [message #788543] Wed, 01 February 2012 23:33 Go to next message
Mike Key is currently offline Mike KeyFriend
Messages: 6
Registered: February 2012
Junior Member
I am interested in using ValuePartioning with Eclipselink 2.3.2. I have a couple of questions that seem somewhat unclear, the first may answer the second by default.

1) Is it possible to use partitioning with Spring? I configure my EclipseLink via Spring's EclipseLinkJpaVendorAdapter and my entity manager (for now) with LocalContainerEntityManagerFactoryBean. This appears to only allow for a single data source (which currently is a DBCP connection pool). It seems unclear to me how I could define multiple pools for partitioning using these classes. For example I can only set one data source in my entity manager from here.

2) I assume if my first question is possible, then I can use an external connection pool (eg. C3P0 or DBCP) to configure as my data sources, even though the property names for each node suggest they are internal EclipseLink pools?

Thanks for any insight here, much appreciated in advance.
Re: JPA Partitioning and Spring [message #789183 is a reply to message #788543] Thu, 02 February 2012 17:57 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You define the additional connection pools using persistence unit properties,

"eclipselink.connection-pool.mypool2.nonJtaDataSource"="<jndi-name>"

The connection pool name is referenced in your partitioning policies, so it is independent of the actually DataSource.

If your DataSource cannot be looked up in JNDI, then you can set it directly. You will need to use a SessionCustomizer for this that gets the ConnectionPool from the ServerSession and configures its Connector on its DatabaseLogin.

You can also use EclipseLink's connection pooling.



James : Wiki : Book : Blog : Twitter
Re: JPA Partitioning and Spring [message #789186 is a reply to message #788543] Thu, 02 February 2012 17:57 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You define the additional connection pools using persistence unit properties,

"eclipselink.connection-pool.mypool2.nonJtaDataSource"="<jndi-name>"

The connection pool name is referenced in your partitioning policies, so it is independent of the actually DataSource.

If your DataSource cannot be looked up in JNDI, then you can set it directly. You will need to use a SessionCustomizer for this that gets the ConnectionPool from the ServerSession and configures its Connector on its DatabaseLogin.

You can also use EclipseLink's connection pooling.


--
James : http://wiki.eclipse.org/EclipseLink : http://en.wikibooks.org/wiki/Java_Persistence : http://java-persistence-performance.blogspot.com/


James : Wiki : Book : Blog : Twitter
Re: JPA Partitioning and Spring [message #789223 is a reply to message #789186] Thu, 02 February 2012 19:03 Go to previous messageGo to next message
Mike Key is currently offline Mike KeyFriend
Messages: 6
Registered: February 2012
Junior Member
Thanks James! I have tried what you said here, I think I'm missing something with the spring config or something...although the error I get is solely from EclipseLink.

Exception Description: Cannot acquire data source [java:comp/env/jdbc/csp-gb].
Internal Exception: javax.naming.NamingException: This context must be accessed through a java: URL
at org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:497)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:109)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.connectInternal(DatasourceAccessor.java:330)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.connectInternal(DatabaseAccessor.java:293)
at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.connect(DatasourceAccessor.java:418)
at org.eclipse.persistence.sessions.server.ConnectionPool.buildConnection(ConnectionPool.java:216)
at org.eclipse.persistence.sessions.server.ExternalConnectionPool.startUp(ExternalConnectionPool.java:146)
at org.eclipse.persistence.sessions.server.ServerSession.connect(ServerSession.java:489)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:633)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:208)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:488)
... 107 more
[Caused by: javax.naming.NamingException: This context must be accessed through a java: URL

The only thing I changed is I added a JNDI resource that is confirmed configured in tomcat. Is this where you meant I would need a SessionCustomizer? The JNDI resource is there and accessible, looks like its not connecting to it properly though.

At this point I'm leaving Spring completely out of the picture and just setting the property in persistence.xml and assuming EclipseLink handles this well below Springs configuration of the entity manager.

Thanks again for your help.
Re: JPA Partitioning and Spring [message #789227 is a reply to message #789186] Thu, 02 February 2012 19:03 Go to previous messageGo to next message
Mike Key is currently offline Mike KeyFriend
Messages: 6
Registered: February 2012
Junior Member
Thanks James! I have tried what you said here, I think I'm missing something with the spring config or something...although the error I get is solely from EclipseLink.

Exception Description: Cannot acquire data source [java:comp/env/jdbc/csp-gb].
Internal Exception: javax.naming.NamingException: This context must be accessed through a java: URL
at org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:497)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:109)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.connectInternal(DatasourceAccessor.java:330)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.connectInternal(DatabaseAccessor.java:293)
at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.connect(DatasourceAccessor.java:418)
at org.eclipse.persistence.sessions.server.ConnectionPool.buildConnection(ConnectionPool.java:216)
at org.eclipse.persistence.sessions.server.ExternalConnectionPool.startUp(ExternalConnectionPool.java:146)
at org.eclipse.persistence.sessions.server.ServerSession.connect(ServerSession.java:489)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:633)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:208)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:488)
... 107 more
[Caused by: javax.naming.NamingException: This context must be accessed through a java: URL

The only thing I changed is I added a JNDI resource that is confirmed configured in tomcat. Is this where you meant I would need a SessionCustomizer? The JNDI resource is there and accessible, looks like its not connecting to it properly though.

At this point I'm leaving Spring completely out of the picture and just setting the property in persistence.xml and assuming EclipseLink handles this well below Springs configuration of the entity manager.

Thanks again for your help.
Re: JPA Partitioning and Spring [message #789252 is a reply to message #789227] Thu, 02 February 2012 19:35 Go to previous messageGo to next message
Mike Key is currently offline Mike KeyFriend
Messages: 6
Registered: February 2012
Junior Member
I have seen that you need a SessionCustomizer for JTA data sources used in this way which give the error I'm seeing. As I'm not using a JTA resource I didn't figure I needed that. Taken from EclipseLink documentation here in the Tomcat-Web-Tutorial examples for Eclipselink (sorry forum wouldn't let me post the URL).

In the section regarding Session Customizer. I just want to validate this is still required when using a non-JTA resource.

I guess the better question I could ask is...is it possible using Spring configuration to pass in the JNDI resource to EclipseLink for both of my data sources? Spring has already done the JNDI lookup, but I can't see how I can just pass EclipseLink the data source Spring has configured.

In Spring I am using the EclipseLinkJpaVendorAdapter.

[Updated on: Thu, 02 February 2012 19:38]

Report message to a moderator

Re: JPA Partitioning and Spring [message #793912 is a reply to message #789252] Wed, 08 February 2012 18:39 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

I think you still needs to use a SessionCustomizer for JNDI on Tomcat. I think you need to set the lookup type on the JNDIConnector.

((JDNIConnector)session.getLogin().getConnector()).setLookupType(JDNIConnector.STRING_LOOKUP)

Please log/vote for the bug on this. There should be a way to use string lookup with using a customizer.



James : Wiki : Book : Blog : Twitter
Previous Topic:MOXy: JSON marshalling not using XMLType's propOrder
Next Topic:IndirectList inserted as parent
Goto Forum:
  


Current Time: Fri Apr 19 02:23:05 GMT 2024

Powered by FUDForum. Page generated in 0.02457 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top