Entity Manager in EJB3
Could someone explain the concept of
1. Entity manager.
2. Types and Purpose of Entity manager
3. How they are injected
Thanks in advance.
A start to covering these questions here:
http://en.wikibooks.org/wiki/Java_Persistence/Runtime
For the meaning of life go here:
http://en.wikipedia.org/wiki/Meaning_of_life
-- James : http://www.eclipselink.org
Similar Messages
-
Problem with non-container managed entity manager
i am working on a project, in which i am using entity beans.i use netbeans, glassfish as application server and toplink as persistence provider .
i created a java class that handles all the operations with the entitys, which means i using non-container managed entity manager.
in the constructor
try{
EntityManagerFactory emf = Persistence.createEntityManagerFactory("voidPU");
entityManager = emf.createEntityManager();
catch(Exception ex){
throw new EJBException(ex.getMessage());
}then i call a function in this class from a servlet
the code of the function
List users = null;
try {
ProgLanguages progLanguage = entityManager.find(ProgLanguages.class, languageId);
users = (List) progLanguage.getUserIdCollection();
catch(IllegalStateException illegalStateException){
throw new EJBException(illegalStateException.getMessage());
catch(IllegalArgumentException illegalArgumentException) {
throw new EJBException(illegalArgumentException.getMessage());
}i got an IllegalArgumentException saying Unknown entity bean class: class vanguard.server.entity.ProgLanguages, please verify that this class has been marked with the @Entity annotation
what confuses me is that sometimes it works and most of the time it does not work, have i made anything wrong?, or there is a problem with any of the tools netbeans, glassfish, or toplink?Is it always the same entity that is reported as 'unknown' ? You mention that it works sometimes but is it the same deployment and the same code that works? The first thing I would verify is that the ear is being created as expected by netbeans. Check the persistence.xml file and verify that all of the classes are listed that will be used as entities.
--Gordon -
How to use application managed entity manager in EJB?
I finish reading The EntityManager Interface in JEE tutorial.
I know I can use container manager entity manager in EJB, but I want to explore how to use application managed entity manager in EJB.
Can I use application managed entity manager in EJB (container management JTA transaction is used)? Where do I should close entity manager if can?
The following is an example from JEE tutorial, but didn't find where to calose entity manager. and can I create mutiple EntityManagerFactory objects and Entity Manager objects to use them in a JTA transaction?
@PersistenceUnit
EntityManagerFactory emf;
EntityManager em;
@Resource
UserTransaction utx;
em = emf.createEntityManager();
try {
utx.begin();
em.persist(SomeEntity);
em.merge(AnotherEntity);
em.remove(ThirdEntity);
utx.commit();
} catch (Exception e) {
utx.rollback();Seems like a very poor example, the whole power of EJBs is to use Container Managed Transactions so you don't NEED to manage the transaction and the entity manager yourself. What you posted is code I would expect in a non-JEE application, or in a piece of code which requires fine-tuned transaction boundaries such as batched data importing logic.
If I were you I'd research JPA in steps.
a) learn about JPA as an API outside of the scope of EJBs (recommended reading: the book 'Pro JPA 2')
b) learn about Container Managed Transactions in EJBs
c) learn about Bean Managed Transactions in EJBs
Right now you're rushing into c). I can understand that it raises many question marks at this point. -
Topic: How to obtain entity manager in application server?
Hey,
How to obtain Entity manger in application server ?
The class is a simple class (no Ejb), and i can call to this class from Ejb or from inner schdeuler process (not container management)
I want that if i call to this calss from Ejb , that the entity manager transaction will join to the global transaction.
Thank youHi,
entity managers outside EJBs can be created using a javax.persistence.EntityManagerFactory.
Regards -
Hey all Well I was just wonder if you guys could give me some insight? I am using the entity manager and It seems like I can do a transaction.. But as I keep doing the transaction to add elements.. It runs fine but then all of a sudden it just hangs? here my code? any insight would be greatly appreciated.. even if its just a theory
selectedCustomer.getLevelIdSellCollection().add(item);
EntityTransaction tx = getEntityManager().getTransaction();
tx.begin();
getEntityManager().merge(Customer);
tx.commit();
getEntityManager().refresh(Customer);
Message was edited by:
jbayuga
Message was edited by:
jbayugaWelcome to the forum.
If you have created either a Roll, or Crawl, with the Animation Preset, then you will want to increase the Duration of that Title, to slow it down. You can do this by click+dragging on the Tail of the Title.
Or, you can create a static Title, then animate it by Keyframing the Fixed Effect>Motion>Position over time. That allows for much more control.
Good luck,
Hunt -
Recommended way of getting entity manager from pojo class
Hi,
In our application we have the need or retrieving entity manager from 'pojo' classes.
More specifically we have singleton classes which act as 'data' repositories and are accessed from both servlets and ejb.
I'm aware that the repositories classes might be problematic, but in the current stage we can't perform significant change in application structure so I am looking for a 'fast' solution as possible.
The best way will be to lookup entityt manager in JNDI, but as I undestand this feature is not avaialabe in weblogic.
I understand that the preffered way for getting entity manager in such situation is by using @PersistenceUnit annotion on the calling location and lookup entityManager by that name in the pojo. This is however problematic for us since since we access the repositories from variouse locations (many different classes).
Possible additional solutions we thought of:
- creating an 'entity manager factory' locator ejb. This is an ejb with no transaction attribute, which has one method getEntityManagerFactory. It injects entityManagerFactory and returns it. This is the fastest soltion to implement. Is this a valid one?
- using application managed entity manager in such situations. We have a problem doing so now because the creation seems to fail for variouse reasons.
What is the recommended way?
Thanks.To obtain an EntityManager instance, first must obtain an EntityManagerFactory instance by injecting it into the application component by means of the javax.persistence.PersistenceUnit annotation:
@PersistenceUnit
EntityManagerFactory emf;
Then, obtain an EntityManager from the EntityManagerFactory instance:
EntityManager em = emf.createEntityManager();
http://download.oracle.com/javaee/5/tutorial/doc/bnbqw.html
Edited by: dvohra16 on Apr 14, 2011 5:06 PM -
Database Entity Manager Concept
Hello Forte-Users,
currently I work with the Concept of the White-Paper:
Forte Database Integration Patterns
Forte Consulting
May 1996
to integrate Database-Access into my Warehouse-Application.
Because the hole Application is delivered step by step and we are new
in using Forte, I use for the first step only the patterns described for
the DBEntityMgr to get a "feeling".
The problem is, that if I use the DBEntityMgr-Concept and have many
BaseClasses to access I have a lot of interface-calls like
GetCustomer,GetProducts,etc..
The Database Session Router will also not solve this "problem" in future,
because the
ApplicationEntityMgr has than the same problem.
Question: Know anyone a way, based on the upon described facilities to use
this strategy with a solution to make more "EntityMgrSO's" to get a smaller
DBEntityMgr-Interface?
The Database Session Router is planed for using when the Application should
be used from more Users and when running the SO's on a WorkGroup-Server.
Question: Know anyone a way there to split the ApplicationEntityMgr?
Every reply is welcome.
Thanks forward to all
Joseph Mirwald
Bachmeier & Sporrer
GERMANY
EMAIL: [email protected]
Don't worry, which bug you wanna have today?...snip
>> The bad part is that now, the "client" of the entity manager
must know
>> which entity manger to call for any particular set of
data. This negates
>> a significant part of the advantage of using the single
interface into the
>> persistence layer.
snip ...
[KUBASADA Manjunatha] We can avoid this problem by having the
EntityMgrSO method determine which entity manager to use. The client can
pass a parameter indicating which object to get. The client call would
look like,
myobject = EntityMgrSO.GetEntity(myobjectindicator);
OR
EnitytMgrSO.GetEntity(output myobj : object);
In the second case, the GetEntity method uses the run time type
of myobj to determine which entity manager to call. In both cases the
EntityMgrSO returns an object of type Object; the client would have to
cast it to the appropriate type.
Don, are there any downsides to this approach ?
Manjunatha Kubasada
Complete Business Solutions Inc.
email : [email protected]
Ph : (248) 488-2088 X 3480
-----Original Message-----
From: Don Nelson [SMTP:[email protected]]
Sent: Saturday, November 29, 1997 4:05 PM
To: Joseph Mirwald
Cc: forte-users
Subject: Re: Database Entity Manager Concept
Joeseph,
The concept of the entity manager having less interfaces is both good
and
bad. The good part is mostly related to development - splitting up
the
calls to the various SQL managers among several entity managers allows
more
flexibility in terms of which classes have to be checked out of the
repository to add to or update the interfaces.
>> The bad part is that now, the "client" of the entity manager
must know
>> which entity manger to call for any particular set of
data. This negates
>> a significant part of the advantage of using the single
interface into the
>> persistence layer.
I've used both strategies in the past, and I tend to stay with one
entity
manager with a large number of interfaces. It moves the
responsibility of
knowing where to get the data from the client to the service, where it
usually belongs. The only real time penalty is when you compile the
partition - there will be more to compile. But since they are just
interafaces, it shouldn't be that big of a deal.
Don
At 10:49 AM 11/28/97 -0500, Joseph Mirwald wrote:
Hello Forte-Users,
currently I work with the Concept of the White-Paper:
Forte Database Integration Patterns
Forte Consulting
May 1996
to integrate Database-Access into my Warehouse-Application.
Because the hole Application is delivered step by step and we are new
in using Forte, I use for the first step only the patterns describedfor
the DBEntityMgr to get a "feeling".
The problem is, that if I use the DBEntityMgr-Concept and have many
BaseClasses to access I have a lot of interface-calls like
GetCustomer,GetProducts,etc..
The Database Session Router will also not solve this "problem" infuture,
because the
ApplicationEntityMgr has than the same problem.
Question: Know anyone a way, based on the upon described facilitiesto use
this strategy with a solution to make more "EntityMgrSO's" to get asmaller
DBEntityMgr-Interface?
The Database Session Router is planed for using when the Applicationshould
be used from more Users and when running the SO's on aWorkGroup-Server.
Question: Know anyone a way there to split the ApplicationEntityMgr?
Every reply is welcome.
Thanks forward to all
Joseph Mirwald
Bachmeier & Sporrer
GERMANY
EMAIL: [email protected]
Don't worry, which bug you wanna have today?
============================================
Don Nelson
Regional Consulting Manager - Rocky Mountain Region
Forte Software, Inc.
Denver, CO
Corporate voice mail: 510-986-3810
aka: [email protected]
============================================
"The good thing about drawing a tiger is that it automatically makes
your
picture fine art." - Hobbes -
How to inherit one enity method and to create entity manager factory
Hi All,
i have totally 5 databases where one database has the connection details of all other 4 databases.i am using EJB 3.0 and using MVC architecture.is there any possibility to get the details in that datbase and create entity manager factory based on that detail.i defined all the database connection in persistence.xml.Hi,
is there any oher possibility to create entity manager factory dynamically? -
A question about entity manager in stateless session bean.
JSR 220 ejbcore, page 47 : stateless session bean: All business object references of the same interface type for the same stateless session bean have the "same object identity", which is assigned by the container.
So, if we have two session beans in client code...
@EJB Cart cart1;
@EJB Cart cart2;
then cart1.equals(cart2)==true
If we declare entity manager in stateless session bean:
@PersistenceContext( unitName="ds" ,type=PersistenceContextType.TRANSACTION)
private EntityManager em;If cart1 and cart2 are the same reference, do we have any problem when using the same reference(maybe the same em? ) to get data from db?If cart1 and cart2 are the same reference, do we have
any problem when using the same reference(maybe the
same em? ) to get data from db?No. In EJB, there is a distinction between the EJB reference and the bean instance.
Each time you make an invocation on an EJB reference for a stateless session bean,
the container can choose any instance of that bean's bean class to process the
invocation. That's true whether you invoke the same reference multiple times or
two difference references to the same bean.
Each bean instance is guaranteed to be single-threaded. -
JPA and Entity manager.
Hi all,
I have a "simple" question:
Should I create a class to manage entity manager and entity manager factory on JPA2?
Why do I ask that? Because I read on J2EE tutorial:
With a container-managed entity manager, an EntityManager instance’s persistence context is automatically propagated by the container to all application components that use the EntityManager instance within a single Java Transaction Architecture (JTA) transaction.
To obtain an EntityManager instance, inject the entity manager into the application component:
@PersistenceContext
EntityManager em;
I'm using JSF2, JPA2, JTA and Glassfish3.1 on the NetBeans 7.0.1.
The wizard that creates the JSF's pages from entity class does a good work but I have some problem in the other classes.
When I call EntityManager it returns null!
The strange thing is that it works properly the first time, when I recall the EntityManager from another xhtml page and from another class the entity manager returns NULL!
So I would understand if the creation of a class for manage the EntityManagerFactory and EntityManager could help me.
Thank you for your future help!Filippo Tenaglia wrote:
Hi all,
I have a "simple" question:
Should I create a class to manage entity manager and entity manager factory on JPA2?That question is far from complete, as the answer to this one is "depends on what you want to do!"
Why do I ask that? Because I read on J2EE tutorial:
With a container-managed entity manager, an EntityManager instance’s persistence context is automatically propagated by the container to all application components that use the EntityManager instance within a single Java Transaction Architecture (JTA) transaction.
To obtain an EntityManager instance, inject the entity manager into the application component:
@PersistenceContext
EntityManager em;
Given this information...
I'm using JSF2, JPA2, JTA and Glassfish3.1 on the NetBeans 7.0.1.That answer to your question is "NO", because you have a container available to you that can do the work (Glassfish). It makes no sense using Glassfish and then purposely ignoring the features it has to offer.
Lets get back to basics: you are doing something wrong here. You have to figure out what, you can only do that if you keep studying and getting a more complete understanding. If you are having trouble realizing that, perhaps you should start over without the help of any wizard at all; wizards are only useful when you are already experienced, right now the fact that code is generated is hindering you a lot because you will have a strong impulse to believe there can be no mistake; unfortunately there is no such safety net. The fact that you used the word "weird" is enough proof of this by the way. There is nothing weird here, just a mistake being made that has to be corrected.
And for the future: what IDE (Netbeans in your case) you use to develop really makes absolutely no difference at all. What is more interesting is which version of Java your are using, which can likely be Java 6 or Java 7 nowadays. -
Can I create two entity manager factoris in one app?
I need to develop two projects, both need JPA access to same data source.
One is an web project, the other is java se project. And web project needs to the some methods inside java se project.
I created two separate JPA set(persistence.xml and entity classes). Both project can run separately however, if I call the methods inside java se project from the web project.
entity manager inside that project won't be created successfully, says error:
oracle.toplink.essentials.exceptions.DatabaseException Internal Exception: java.sql.SQLException: No suitable driver found
I am very confident that mysql driver lib has been added for both projects.
Does anyone know what is wrong here? Thanks!Yes. Reduce the number of FDM applications you are creating. You can have multiple target system adapters in a single FDM application (i.e. a single database only required). There is no need to create a new application for each target system.
-
DebugMBean not found when creating EJB3 Entity Manage
Hi,
Got exception when test my ejb3 entity bean out of container. weblogic.jar which I get from weblogic 10.3 has been included in he classpath.
I checked the weblogic.jar, it does not have DebugMBean.class. I believe it is a weblogic bug. Can anybody have solution to fix it?
Thanks,
Bruce Xie
public EntityManager createEntityManager() {
if(emf == null) {
emf = Persistence.createEntityManagerFactory(persistenceUnitName);
return emf.createEntityManager();
Exception in thread "Main Thread" java.lang.NoClassDefFoundError: weblogic/management/configuration/DebugMBean
at java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.lang.ClassLoader.findBootstrapClass0(ClassLoader.java:891)
at java.lang.ClassLoader.loadClass(ClassLoader.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at weblogic.xml.jaxp.RegistrySAXParserFactory.<clinit>(RegistrySAXParserFactory.java:27)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at javax.xml.parsers.FactoryFinder.newInstance(FactoryFinder.java:148)
at javax.xml.parsers.FactoryFinder.findJarServiceProvider(FactoryFinder.java:298)
at javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:224)
at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:128)
at org.apache.openjpa.lib.xml.XMLFactory.<clinit>(XMLFactory.java:60)
at org.apache.openjpa.lib.meta.XMLMetaDataParser.parseNewResource(XMLMetaDataParser.java:352)
at org.apache.openjpa.lib.meta.XMLMetaDataParser.parse(XMLMetaDataParser.java:320)
at org.apache.openjpa.lib.meta.XMLMetaDataParser.parse(XMLMetaDataParser.java:296)
at org.apache.openjpa.lib.meta.XMLMetaDataParser.parse(XMLMetaDataParser.java:268)
at org.apache.openjpa.persistence.PersistenceProductDerivation$ConfigurationParser.parse(PersistenceProductDerivation.java:510)
at org.apache.openjpa.persistence.PersistenceProductDerivation.parseResources(PersistenceProductDerivation.java:360)
at org.apache.openjpa.persistence.PersistenceProductDerivation.load(PersistenceProductDerivation.java:326)
at org.apache.openjpa.persistence.PersistenceProductDerivation.load(PersistenceProductDerivation.java:161)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:77)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:109)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:53)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:84)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
at JPATestBase.createEntityManager(JPATestBase.java:50)
at JPATestBase.<init>(JPATestBase.java:23)
at JPATestBase.main(JPATestBase.java:17)Hi,
I do not see the DebugMBean class anywhere in the 3 com.bea.core.management.*.jar or 2 com.bea.core.mbean.*.jar libraries in the "modules" directory on WebLogic 10.3.0 - there is no longer a single webllogic.jar to check.
As a workaround try switching your persistence provider to EclipseLink by adding the following line to your persistence.xml and adding the EclipseLink library via the patching instructions below. If you are running WebLogic 10.3.1 then you will only need the provider line - as EclipseLink is shipped in this version.
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
http://wiki.eclipse.org/EclipseLink/Examples/JPA/WebLogic_Web_Tutorial#Option_2:_Apply_Smart_Update_Patch_-Recommendedfor_10.3.0.0
Also, there is a workaround to change the SAX parser you are using that is causing this issue - in the WebLogic forum that may solve this.
NoClassDefFoundError: weblogic/management/configuration/KernelDebugMBean
System.setProperty("javax.xml.parsers.DocumentBuilderFactory","org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl");
thank you
/michael
www.eclipselink.org -
I can not save new object using JPA entity manager, please help
I am using Spring 3 with JPA to access database, I tried to persist object, but failed. This is what I do:
1) Config:
<tx:annotation-driven transaction-manager="txManager" proxy-target-class="true"/>
<bean id="txManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="emf" />
</bean>
<bean id="emf"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<property name="loadTimeWeaver">
<bean
class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
<property name="persistenceUnitName" value="memberPU"></property>
</bean>
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="MYSQL" />
<property name="showSql" value="true" />
<property name="generateDdl" value="false" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url"
value="jdbc:mysql://localhost:3306/springinaction?createDatabaseIfNotExist\=true&useUnicode\=true&characterEncoding\=utf-8&enableQueryTimeouts\=false" />
<property name="username" value="root" />
<property name="password" value="" />
<property name="initialSize" value="5" />
<property name="maxActive" value="10" />
</bean>
2) Persistence.xml:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0">
<persistence-unit name="memberPU" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.hbm2ddl.auto" value="validate" />
</properties>
</persistence-unit>
</persistence>
3) Domain:
@Entity
@Table(name = "members")
public class Spitter {
@Id
@Column(name = "id")
@GeneratedValue(generator = "InvSeq")
@SequenceGenerator(name = "InvSeq", sequenceName = "group table seq01", allocationSize = 5)
private int id;
@Column
private String firstName;
@Column
private String lastName;
@Column
private int age;
gettters and setters...
4) Dao:
@Repository
@Transactional
public class SpitterDao {
@PersistenceContext
private EntityManager em;
public void addSpitter(Spitter spitter){
Spitter s = new Spitter();
//s.setId(null);
s.setFirstName("Frank");
s.setLastName("wqrewreqwr");
s.setAge(45);
System.out.print("Persisting into tDB here ");
this.em.merge(s);
this.em.persist(s);
//this.em.flush();
//this.em.getTransaction().commit();
If I do not call em.flush(), no error throws, and program is executed succesfully. BUT nothing is saved to DB. IF I used em.flush(), I got errormsg - "No Transaction", but the Dao is already annoted with @Transactional.
Reading through the JPA is no problem.
I tried different solutions heavily, but no result. Pleaes anyone point out what's the error and why object can not be serialized to DB.
Thanks very muchHello,
You might try posting on a different forum (possibly a Spring forum) as this one is more specifically aimed at TopLink/EclipseLink which you are not using.
It appears the em is not associated to the transaction, but I can't suggest much other than point you at an EclipseLink Spring integration demo such as described here
http://www.vogella.de/java.html
or http://blog.springsource.org/2008/07/17/using-eclipselink-on-the-springsource-application-platform/
which might show settings that are missing or incorrect.
If you switched to using EclipseLink as the JPA provider i would suggest uploading the log file as that might detail how or why it is not being assocated to the transaction.
Best Regards,
Chris -
Bidirectional entity access problem (EJB3)
I made some tests with EJB3 entity beans.
I have simple entity USERS, where is itself (FK-PK) relation PARENT_ID -> USER_ID.
Appropriate part of persistent class Users is:
@ManyToOne
@JoinColumn(name = "PARENT_ID", referencedColumnName="USER_ID")
public Users getUsers() {
return this.users;
}end servers side:
@OneToMany(mappedBy="users", cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
public Set<Users> getUserses() {
return this.userses;
}When I do something, specially call setUser(childInstance) to point the parent instance, on MenyToOne side of association it works.
But when I try to do similar on OneToMany side, like calling:
getUserses().add(childInstance)or
getUserses().remove(childInstance)The changes are only transient and there's not saved into the database.
Although the entity class has bidirectional annotations, it works like unidirectional.
Thanks for some help
KMIn JPA you must always set both sides of the relationship.
See,
[http://en.wikibooks.org/wiki/Java_Persistence/Relationships]
-- James : [http://www.eclipselink.org] -
Entity manager outside of entities jar
Hi,
Is it possible to keep perisitence unit (persistence.xml) in different jar than etities?
I would like to store all entities in one jar and treat them as DTO and put that jar in several modules (web module, EJB module), but logic of data manipulations store only in business module.
For me it doesn't work even in simple example:
public static void main(String[] args) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("TestPU");
EntityManager em = emf.createEntityManager();
Object o = em.find(pkg.Uzytkownik, new Integer(10));
I get exception:
Exception in thread "main" java.lang.LinkageError: loader constraint violation: loader (instance of sun/misc/Launcher$AppClassLoader) previously initiated loading for a different type with name "pkg.SloStawka"
at java.lang.ClassLoader.defineClass1(Native Method)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.Class.forName(Class.java:247)
at oracle.toplink.essentials.internal.security.PrivilegedAccessHelper.getClassForName(PrivilegedAccessHelper.java:97)
On the web server with similar code in EJB module I get:
Caused by: java.lang.IllegalArgumentException: Unknown entity bean class: class pkg.Uzytkownik, please verify that this class has been marked with the @Entity annotation.
at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.findInternal(EntityManagerImpl.java:306)
at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.find(EntityManagerImpl.java:148)
In all modules I have only one class with name Uzytkownik and it contains:
@Entity
@Table(name = "uzytkownik")
public class Uzytkownik ...
The same result is both with Toplink 9.1 build: b36-rc and Toplink 11
best regards,
arturDorbsz,
Strangely, I tried it again about a month later, and it worked! I have no explanation other than perhaps the container had malfunctioned and it needed to be restarted.
Another thing, is that it may+ have started working about the time that I began using the @Version entity annotation.
So here is that I would try in this order:
1. Restart the container
2. Try adding the @Version annotation to a field on the entity (will need a database column to correspond to)
3. If 1 and 2 fail, you can create a named query with a Toplink hint that informs Toplink not to get the entity from the cache, so in stead of using refresh, you would execute that query.
I was doing number 3 for a while, and it works, but it is obviously not the best solution. I don't have a link at the moment, but if you goolge with keywords like "toplink refresh hint cache" you should find an example of how to do it. Oracle also has all of the Toplink hints documented.
If you have a lot of trouble finding an example, I could possibly post my named query that did this. Only go this route as a last resort though.
Kurzweil4
Maybe you are looking for
-
How-to sync my Macbook pro with my main iTunes library on another computer?
I bet that question came up already, but I can't easily find any reference to it. Anyways, here I go. I have a desktop @ home with 1TB of disk space, and I'm using a Macbook Pro as my work laptop. I'd like to be able to sync up my Macbook Pro as if i
-
I have had this issue ever since Flash CS3, but I now see it has persisted in Flash CS4 as well and I would like to see it resolved. When drawing with the brush tool, using a Cintiq 21UX, and also on a Tablet PC, under WinXP, I have been experiencing
-
Disk Utility and 320GB hard drive
I just installed a WD Scorpio 320GB hard drive in my first-generation MacBook. Everything works fine in normal use. When I go to Disk Utility, however -- using the new internal HD as my startup disk -- the "Repair Disk" button is grayed out. The othe
-
I want to know how to check my balance on an itune card that has been activated?
Hi I purchased an itunes card and just wanted to know how to check the remaining balance on the card. Somewhat new to this.
-
Dynamically switch printer tray from concurrent program in Oracle Apps 11i
Hi All, We have a requirement to dynamically switch printer tray from concurrent program . In the application we had a printer "*Printer1*" defined ,the printer (physical) printer have two trays and it always pick paper from Lower tray To test the fu