-
1. Re: How to Extend Persistence Context Programatically
monkeyden Oct 1, 2007 12:19 PM (in response to bravefencer)Have you tried the unitName attribute?
-
2. Re: How to Extend Persistence Context Programatically
bravefencer Oct 1, 2007 12:34 PM (in response to bravefencer)hello,
yes i tried. but i got an exception:
Field javax.persistence.EntityManager QMoDIS.backend.BussinessTier.session.SessionObjektAuswahl.em @PersistenceUnit in error: EMPTY STRING unitName and there is more than one scoped persistence unit
That's the problem, because i have more than one persistence-Unit. -
3. Re: How to Extend Persistence Context Programatically
bravefencer Oct 1, 2007 12:35 PM (in response to bravefencer)i want to extend the persistence context for all possible persistence-contexts, that may be injected.
-
4. Re: How to Extend Persistence Context Programatically
monkeyden Oct 1, 2007 1:44 PM (in response to bravefencer)What value did you provide for unitName? Was it a value from your persistence.xml file?
<persistence-unit name="someDB"> ... </persistence-unit>
@PersistenceContext(unitName="someDB")
I think this is the way it's done anyway. Personally, I use SMPC. -
5. Re: How to Extend Persistence Context Programatically
pmuir Oct 1, 2007 2:00 PM (in response to bravefencer)An SMPC is equivalent to an extended persistence context for conversationally scoped components.
-
6. Re: How to Extend Persistence Context Programatically
bravefencer Oct 1, 2007 4:03 PM (in response to bravefencer)i have more than one persistence unit defined in persistence.xml, because i'am using more than one database.
But for all possible units i have defined in the persistence.xml i must have an extended persistence context. -
7. Re: How to Extend Persistence Context Programatically
bravefencer Oct 1, 2007 4:07 PM (in response to bravefencer)is there a way to define the extension of the persistence contexts directly in the persistence.xml instead of annotating this behaviour at the entitymanager definition?
-
8. Re: How to Extend Persistence Context Programatically
bravefencer Oct 1, 2007 4:13 PM (in response to bravefencer)i used SMPC(for example):
<core:managed-persistence-context name="myManagername" auto-create="true" persistence-unit-jndi-name="java:/myjndiname"> </core:managed-persistence-context>
but the context is not extended, because
in the code i get the ref to the Entitymanger i described further, but the Dataselection Model will not work in my stateful session beans, so it's not extended. -
9. Re: How to Extend Persistence Context Programatically
monkeyden Oct 1, 2007 4:17 PM (in response to bravefencer)Seam bijection depends on variable name. Try this:
@In(create=true) private EntityManager myManagername;
-
10. Re: How to Extend Persistence Context Programatically
bravefencer Oct 1, 2007 4:24 PM (in response to bravefencer)the problem is that the name of the entitymanager will be determined at runtime. so i can't put the static variable name before runtime in my code.
-
11. Re: How to Extend Persistence Context Programatically
monkeyden Oct 1, 2007 4:33 PM (in response to bravefencer)Not sure why it needs to be determined at runtime but have you tried:
EntityManager em = (EntityManager)Component.getInstance(someRuntimeString, true);
??? -
12. Re: How to Extend Persistence Context Programatically
bravefencer Oct 1, 2007 4:39 PM (in response to bravefencer)yes. look at my first posting ;)
but if i inititialize the Entitymanager on that way(in some SFSB) the DataSelection Model will not work properly. It works only if in Annotate the Entitymanager Variable with @PersistenceContext(unit-name"myunitname", type=PersistenceContextType.EXTENDED).
But then i must hardcode a unit-name, and thats the problem. -
13. Re: How to Extend Persistence Context Programatically
bravefencer Oct 1, 2007 4:40 PM (in response to bravefencer)it's needed at runtime, because, every EntityManager has a binding to a database and which Database will be used, is decided at runtime.
-
14. Re: How to Extend Persistence Context Programatically
bravefencer Oct 1, 2007 4:44 PM (in response to bravefencer)hmm,
i define the Entitymanager on that way:EntityManager em = (EntityManager)Component.getInstance(someRuntimeString);
Without the second Parameter set on true. maybe thats the problem ?