Re: CMP failed with 3 layered Object structure
No my contact class is just out of a few strings like "firstName, surName, street, city, zipcode, country and so on". -- View this message in context: http://openejb.979440.n4.nabble.com/CMP-failed-with-3-layered-Object-structure-tp4655311p4655582.html Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: CMP failed with 3 layered Object structure
Your haven't defined the transaction scope on your ejb methods. Try adding the annotation @TransactionAttribute(TransactionAttributeType.REQUIRED) to your getCustomer method... @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public Customer getCustomer( String customerId, String sessionId) throws OpenflowException{ Session session = sessionBean.isSessionValid(sessionId); if(session!=null) { Customer customer = (Customer) entityManager.find(Customer.class, customerId); if(customer==null) { throw new OpenflowException("Customer does not exists >>> "+customerId); } customer.getContactList(); return customer; } return null; } -- View this message in context: http://openejb.979440.n4.nabble.com/CMP-failed-with-3-layered-Object-structure-tp4655311p4655586.html Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: CMP failed with 3 layered Object structure
I am not @ work. If I am annotate this method, will I need still the getContacts().size()-method, to get no lazyLoading Exception? -- View this message in context: http://openejb.979440.n4.nabble.com/CMP-failed-with-3-layered-Object-structure-tp4655311p4655588.html Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Tomee Hibernate Session JNDI
I prefer the second option using resources.xml. What value would openejb/Resource/nameUsed have to bind hibernate.session_factory_name in JNDI? Sorry, I have not used this with Tomcat before. -- View this message in context: http://openejb.979440.n4.nabble.com/Tomee-Hibernate-Session-JNDI-tp4655576p4655589.html Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Tomee Hibernate Session JNDI
The second needs to define a tomee resource (look dynamic datasource sample). Imo that's harder Le 13 juin 2012 17:02, "zeeman" a écrit : > I prefer the second option using resources.xml. What value would > openejb/Resource/nameUsed have to bind hibernate.session_factory_name in > JNDI? > > Sorry, I have not used this with Tomcat before. > > -- > View this message in context: > http://openejb.979440.n4.nabble.com/Tomee-Hibernate-Session-JNDI-tp4655576p4655589.html > Sent from the OpenEJB User mailing list archive at Nabble.com. >
DataSource tomee.xml
My web app is using the datasource that i set in tomee.xml like this: JdbcDriver com.mysql.jdbc.Driver JdbcUrl jdbc:mysql://localhost:3306/mydb UserName myuser Password mypass JtaManaged true How can i set this configuration inside my app (not in the server)? --- *SCJA. José Luis Cetina* ---
Re: DataSource tomee.xml
Put it in meta-inf/resources.xml Le 13 juin 2012 18:52, "José Luis Cetina" a écrit : > My web app is using the datasource that i set in tomee.xml like this: > > > JdbcDriver com.mysql.jdbc.Driver > JdbcUrl jdbc:mysql://localhost:3306/mydb > UserName myuser > Password mypass > JtaManaged true > > > How can i set this configuration inside my app (not in the server)? > > --- > *SCJA. José Luis Cetina* > --- >
Re: DataSource tomee.xml
Hi, Why not in META-INF/context.xml ? Is there any difference betweeb context.xml and resources.xml? As TomEE is supposed to "bet tomcat" I'd configure a datasource the tomcat way, unless I'm missing something. And by the way, can I configure other kinds of resources, say JMS destinations, in context.xml and forget about resurces.xml? []s, Fernando Lozano Put it in meta-inf/resources.xml Le 13 juin 2012 18:52, "José Luis Cetina" a écrit : My web app is using the datasource that i set in tomee.xml like this: JdbcDriver com.mysql.jdbc.Driver JdbcUrl jdbc:mysql://localhost:3306/mydb UserName myuser Password mypass JtaManaged true How can i set this configuration inside my app (not in the server)? --- *SCJA. José Luis Cetina* ---
Re: DataSource tomee.xml
Can you configure the jta or not aspect in context.xml? Le 13 juin 2012 19:11, "Fernando Lozano" a écrit : > Hi, > > Why not in META-INF/context.xml ? > > Is there any difference betweeb context.xml and resources.xml? As TomEE is > supposed to "bet tomcat" I'd configure a datasource the tomcat way, unless > I'm missing something. > > And by the way, can I configure other kinds of resources, say JMS > destinations, in context.xml and forget about resurces.xml? > > > []s, Fernando Lozano > > Put it in meta-inf/resources.xml >> Le 13 juin 2012 18:52, "José Luis Cetina" a écrit >> : >> >> My web app is using the datasource that i set in tomee.xml like this: >>> >>> >>> JdbcDriver com.mysql.jdbc.Driver >>> JdbcUrl jdbc:mysql://localhost:3306/**mydb >>> UserName myuser >>> Password mypass >>> JtaManaged true >>> >>> >>> How can i set this configuration inside my app (not in the server)? >>> >>> --**--**--- >>> *SCJA. José Luis Cetina* >>> --**--**--- >>> >>> > >
Re: Deploying Pet-catalog
Ok it works well! I did some small changes. (Annotation, JTA...) Thanks Romain! -- View this message in context: http://openejb.979440.n4.nabble.com/Deploying-Pet-catalog-tp4655421p4655597.html Sent from the OpenEJB User mailing list archive at Nabble.com.
simple db-jpa-ejb-servlet
Hello, I'm trying to build simple test application with following structure: servlet-ejb-jpa-database Application works well, but when I try to call from servlet ejb, witch call jpa I got error at servlet. Data from db is correctly return via jpa becouse I see it in ejb classs using simple System.out.println. Additional I call simple ejb method sayHello (returning just text) without connection to db and it works well. So at this moment I haven't idea what is wrong. It you would like to see my maven project, it's here: http://iem.pw.edu.pl/~wojciecs/test_ejb_jpa_servlet.7z. I think problem at communication between servlet and ejb. I use tomcat 7.0.27 with openejb 4 Best Regards sw -- View this message in context: http://openejb.979440.n4.nabble.com/simple-db-jpa-ejb-servlet-tp4655596.html Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Tomee Hibernate Session JNDI
I like it to be as simple as possible. The first option is easier. Is unwrapping the Hibernate session from EMF and setting it in JNDI would be done in Java code not xml files? But I don't see how is this going to work, because when app is deployed the EMF will be set. So I have to bind the session factory in JNDI when EMF is set. Right? Could you provide more details place? Some code will help and JNDI value to bind sesstion factory with. -- View this message in context: http://openejb.979440.n4.nabble.com/Tomee-Hibernate-Session-JNDI-tp4655576p4655600.html Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Tomee Hibernate Session JNDI
here how to declare a resource: 1) create a META-INF/foo/service-jar.xml 2) put in: 3) implement SessionUnwrapper to unwrap the session 4) declare a resource of type defined in the previous file and provider="foo:my-id": 5) use jndi name: openejb/Resource/bar that's not "easy" but hibernate is not jpa i think there is ither way to do so, and i can't get why jndi is mandatory... - Romain 2012/6/13 zeeman > I like it to be as simple as possible. The first option is easier. Is > unwrapping the Hibernate session from EMF and setting it in JNDI would be > done in Java code not xml files? > > But I don't see how is this going to work, because when app is deployed the > EMF will be set. So I have to bind the session factory in JNDI when EMF is > set. Right? > > Could you provide more details place? Some code will help and JNDI value to > bind sesstion factory with. > > -- > View this message in context: > http://openejb.979440.n4.nabble.com/Tomee-Hibernate-Session-JNDI-tp4655576p4655600.html > Sent from the OpenEJB User mailing list archive at Nabble.com. >
Re: simple db-jpa-ejb-servlet
Hi, just to be sure: you call a remote ejb which returns a list of non serializable entities? - Romain 2012/6/13 slawek > Hello, > I'm trying to build simple test application with following structure: > servlet-ejb-jpa-database > Application works well, but when I try to call from servlet ejb, witch call > jpa I got error at servlet. Data from db is correctly return via jpa > becouse > I see it in ejb classs using simple System.out.println. > Additional I call simple ejb method sayHello (returning just text) without > connection to db and it works well. So at this moment I haven't idea what > is > wrong. It you would like to see my maven project, it's here: > http://iem.pw.edu.pl/~wojciecs/test_ejb_jpa_servlet.7z. I think problem at > communication between servlet and ejb. I use tomcat 7.0.27 with openejb 4 > > Best Regards > sw > > -- > View this message in context: > http://openejb.979440.n4.nabble.com/simple-db-jpa-ejb-servlet-tp4655596.html > Sent from the OpenEJB User mailing list archive at Nabble.com. >
Re: simple db-jpa-ejb-servlet
Solved, this was a problem - thank you! Best Regards sw -- View this message in context: http://openejb.979440.n4.nabble.com/simple-db-jpa-ejb-servlet-tp4655596p4655603.html Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: CMP failed with 3 layered Object structure
I may have misunderstood your current issue. It seems you are able to get a successful response if you call the getContactList().size() method before returning from your method. If that is the case then adding the @TransactionAttribute will probably not change anything. The issue you are having is really common and happens everywhere you use JPA entities as objects that you pass across transaction boundaries. As soon as the JPA entity is detached, which happens when the transaction commits at the end of your method, you can't automatically load lazy-loaded attributes. Because your method is a webservice operation, the response gets marshalled by JAXB into XML which is when the getContactList() call would be happening after the transaction has committed. The same issue would also happen if you got a Customer entity in a servlet within a transaction and then passed it to a JSP page for rendering and that JSP page tried to call the getCustomerList method. There are several ways of solving this problem. One way in web applications is to use a servlet filter to start and end the transaction so that the JSP page rendering would happen within the same transaction that the Customer entity was retrieved from the database. In this case, the Customer entity is not detached and so the JSP page call to getContactList() would cause the EntityManager to retrieve the data from the database. I'm not sure if there is a similar mechanism you could use for a webservice. Perhaps there is some interceptor you could use around the getCustomer method that could start and commit the transaction after the XML serialization has occurred. Another way is to design your app so you don't use JPA entities as data transfer objects (DTOs). Create another package of dto java beans that are used explicitely for this purpose. Then create stateless ejbs that populate DTOs from your JPA entities within a transaction. The DTO object would then be returned from your webservice and be guaranteed to have all the state already loaded. Although this way sounds like alot more work and i may get flamed for suggesting it, i personally prefer this approach because it takes away the uncertainty about what is or isn't loaded that you always get with JPA entities. Another way is to do as you are currently doing and make sure you call methods that you think are going to be called on the Customer object after you return it. As you have said, this way is not great because you have to guess what lazy loaded attributes the caller of your method is interested in. If you don't like using the method calls to load the lazy-loaded attributes, an alternative is to create a JPA query using the "FETCH" keyword to perform an eager fetch of the lazy loaded attributes. eg. entityManger.createQuery("SELECT c FROM Customer c LEFT JOIN FETCH c.contactList WHERE c.id = :id").setParameter("id", customerId).getSingleResult(); -- View this message in context: http://openejb.979440.n4.nabble.com/CMP-failed-with-3-layered-Object-structure-tp4655311p4655609.html Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Tomee Hibernate Session JNDI
This complete small snippet shows how to get it working with JPA and an EJB container, but I don't know the steps needed for Tomee. The guide is for Jboss. https://community.jboss.org/wiki/HibernateStatisticsWithJPAUsingAMbean What is the equivalent on Tomee? Thanks! -PS Ya, I'm not sure why the session factory needs to be registered. Stupid RedHad. -- View this message in context: http://openejb.979440.n4.nabble.com/Tomee-Hibernate-Session-JNDI-tp4655576p4655610.html Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Tomee Hibernate Session JNDI
Maybe the easier is to extendq the mbean and register it yourself no? - Romain Le 14 juin 2012 04:56, "zeeman" a écrit : > This complete small snippet shows how to get it working with JPA and an EJB > container, but I don't know the steps needed for Tomee. The guide is for > Jboss. > > https://community.jboss.org/wiki/HibernateStatisticsWithJPAUsingAMbean > > What is the equivalent on Tomee? Thanks! > > -PS > Ya, I'm not sure why the session factory needs to be registered. Stupid > RedHad. > > -- > View this message in context: > http://openejb.979440.n4.nabble.com/Tomee-Hibernate-Session-JNDI-tp4655576p4655610.html > Sent from the OpenEJB User mailing list archive at Nabble.com. >