[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Overwrite session manager settings
|
persistence.xml: http://pastebin.com/d1ace8bf6
source: http://pastebin.com/f34fbc64b
log: http://pastebin.com/f1ee20524
I've added a few comments to the source to make it obvious what was
expected and what was the actual result.
> Correction - please also create EM for each of the factories (don't
pass new connection properties to createEM)
I'm sorry, I just saw this mail now and don't have the time to change
my example... if you still need it, I'll do it tomorrow.
Keep in mind that I know there are several things I'm doing wrong,
that I learned from the last couple of emails:
- not passing connection info to createEMF
- not setting EXCLUSIVE_CONNECTION_MODE = Always for instanceEMF
- not setting CACHE_SHARED_DEFAULT = false for instanceEMF
The point is that instanceEMF still shouldn't just take connection
data from some other EMF (clusterEMF in this case, which is never even
used).
Regards,
Jaka
On 2. Apr 2009, at 22:14, Andrei Ilitchev wrote:
Could you please post
1) persistence.xml;
2) the source - which calls createEMF for both persistence units;
3) the log set to finest ("eclipselink.logging.level" "FINEST")
----- Original Message ----- From: "Jaka Jančar" <jaka@xxxxxxxxx>
To: "EclipseLink User Discussions" <eclipselink-users@xxxxxxxxxxx>
Sent: Thursday, April 02, 2009 3:32 PM
Subject: Re: [eclipselink-users] Overwrite session manager settings
I didn't know that... it seems there's a weird bug here.
Persistence.xml has no properties, they're all passed to
Persistence.createEMF like I wrote below.
If create instanceEMF without creating clusterEMF first, I get the
following when doing instanceEMF.createEM() for the first time:
"Unable to acquire a connection from driver [null], user [null] and
URL [null]. Verify that you have set the expected driver class and
URL."
Good.
However if I create clusterEMF (which is completely unrelated and has
a different PU) first, with an URL, and don't even call createEM on it
(so the connection pool isn't even initialized), then create
instanceEMF afterwards (without an URL) and call
instanceEMF.createEM(with an URL), somehow connections with
clusterEMF's URL will be created and the exception thrown because of
the invalid schema.
Jaka
On 2. Apr 2009, at 21:13, Andrei Ilitchev wrote:
"jdbc:mysql://host/ global" specified in persistence.xml for both
persistence units?
Each persistence unit *must* have connection string (or data
source) because the session underneath the factory is connected
before createEMF method returns.
----- Original Message ----- From: "Jaka Jančar" <jaka@xxxxxxxxx>
To: "EclipseLink User Discussions" <eclipselink-users@xxxxxxxxxxx>
Sent: Thursday, April 02, 2009 2:47 PM
Subject: Re: [eclipselink-users] Overwrite session manager settings
The connection string (JDBC_URL) is not the same, that's why it
puzzles me. The host however is.
The steps that I do are:
- clusterEMF = createEMF("ClusterPU", JDBC_URL="jdbc:mysql://host/
global"...)
- clusterEMF.createEM() and do some work with it
- instanceEMF = createEMF("InstancePU", NO JDBC URL!)
(will have to disable shared caches here like you told me)
- instanceEM = instanceEMF.createEM(JDBC_URL="jdbc:mysql://host/
instance_<N>"...)
- instanceEM.find(Foo.class, id)
At the last step, I get the error "Table 'global.foo' doesn't exist".
Database "global"?! From clusterEMF?!
Reading the docu, I would think that each EMF (server session) has
its
own connection pool and it's own cache. Is that not correct?
I understand that, as you told me, I will have to isolate caches of
EMs of the second EMF. But I still don't understand how a completely
unrelated URL from another EMF was used and I would very much like to
know that.
Regards,
Jaka
On 2. Apr 2009, at 16:46, Andrei Ilitchev wrote:
You must use some connections in the second EMF, I am assuming
that connection string is the same as in the first EMF.
Eclipselink uses by default shared cache for all objects it
handles, so consider defining the separate cache for the classes
you will handle in EM created with connection strings.
Defining of non-shared caches is done when EMF is created by
passing the properties to createEMF (or specifying the properties
in persistence.xml):
//for each class that requires isolated cache
"eclipselink.cache.shared.myPackage.MyClass" "false"
//alternatively you can use a single property in case all classes
require isolated cache
"eclipselink.cache.shared.default" "false"
To createEM along with a new connection properties, pass:
"eclipselink.jdbc.exclusive-connection.mode" "Isolated"
----- Original Message ----- From: "Jaka Jančar" <jaka@xxxxxxxxx>
To: "EclipseLink User Discussions" <eclipselink-users@xxxxxxxxxxx>
Sent: Thursday, April 02, 2009 7:42 AM
Subject: Re: [eclipselink-users] Overwrite session manager settings
Hi Tom,
I'm having a problem with this approach: the wrong connections are
being used for the persistence units.
I have two Persistence Units defined in persistence.xml:
ClusterPU and
InstancePU. The EMF for ClusterPU is created normally, supplying
JDBC
data and not overriding it in createEM(). The EMF for InstancePU is
created without supplying JDBC data and setting it each time in
createEM().
After the EMFs are created, I create an EM for ClusterPU, the pool
is
initialized and all works fine for ClusterPU.
The problem is with InstancePU (the one with per-EM JDBC
parameters):
If I save an entity (instanceEm.persist(entity)) a new connection is
established and all works fine. However if I try to load an entity
(instanceEm.find(entityClass, entityId)), a connection from
ClusterPU
will be used, instead of a new one being created, which is
completely
incorrect!
Any ideas?
Jaka
On 19. Mar 2009, at 20:39, Jaka Jančar wrote:
Hmm... this is awesome, I'll check it out.
Hibernate does not support this at all, btw :)
Jaka
On 19. Mar 2009, at 19:50, Tom Ware wrote:
Hi Jaka,
I just spoke to a colleague and he mentioned that the behavior
is exposed through properties.
The key is to create a working EntityManagerFactory with the
strategy listed below. (i.e. Provide working connection
information at the creation of the EMF)
Once you have done that, you can create EntityManagers with
alternate connection information using the properties in
org.eclipse.persistence.config.EntityManagerProperties. Note:
They are the same strings as the ones you use for
EntityManagerFactory creation. The limitation here is that you
must connect to a database that uses the same EclipseLink
DatabasePlatform.
Once again, the recommended approach for most applications is
to use the settings in EntityManagerFactory. The
additional functionality is available for applications that
have more complicated connection requirements.
-Tom
Jaka Janc(ar wrote:
Tom,
is it possible to specify the database server on an
EntityManager basis?
In other words, what can you do if you want to connect to
loads of different hosts, but don't want to recreate
EntityManagerFactory for each one (since that takes ages).
Jaka
On 19. Mar 2009, at 19:23, Tom Ware wrote:
Hi Phil,
In EclipseLink, EntityManagerFactory holds the object that
controls database connections. As a result you need to
provide the database properties to the EntityManagerFactory
at creation time. (In the bootstrap API, a Map can be
provided to the
Persistence.createEntityManagerFactory(String, Map) method.)
If you need to regulate these things on an EntityManager
basis, there is some EclipseLink specific API that can be used
to do that, but for most people, the general API is sufficient.
-Tom
Philipp Kursawe wrote:
Is it possible to overwrite the settings made in the
persistence.xml when creating the EntityManager using an
EntityManagerFactory.create(Map)?
It seems like that the properties I am handing in are not
valued.
Is it in any other way possible to set certain
persistence.xml values from within the program? I mean I
cannot seriously be asked to put login credentials inside a
JAR?
I would like the user to configure those values and feed
them to EclipseLink programmatically not from the
persistence.xml.
Thanks for your help!
Phil
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users