[JBoss Seam] - Re: Does DataModelSelection work in a Stateless Session Bean
by petemuir
"twocoasttb" wrote : I don't see why this finder bean itself should require any state. Am I wrong? It certainly shouldn't have to around in SESSION scope.
It needs some state - a stateless bean looses state between each invocation - it is invoked update data model (i think?) to set the datamodel selection, and then in INVOKE_APPLICATION to call the action - the state is lost between these. Further, you need to hold the state of the datamodel between the two requests - this is due to how JSF works (the restore view phase). The PAGE or CONVERSATION scope is ideal for this
[qupte]Don't ever set var="org" in a dataTable. Doing so causes Seam to go nuts searching contexts and it eventually throws an exception because can't find a property called 'jboss' in the entity bean. Should I report this as a bug? I'd be happy to provide a test case. Using var="o" changes the behavior completely.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4008892#4008892
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4008892
17 years, 10 months
[EJB 3.0] - persistance.units NOTYETINSTALLED
by z3r0
Hi,
I use JBoss 4.0.5 (with EJB3 support) and I develop with Eclipse 3.2.1/WTP 1.5.2.
I try to deploy EJB3s under JBoss, but I'm not abble to access to the persistance manager.
My first EJB Session Stateless runs well :
HelloService.java :
package com.test.jboss.ejb3;
|
| import javax.ejb.Local;
|
| @Local
| public interface HelloService {
| public String hello(String name);
| }
HelloServiceBean.java :
package com.test.jboss.ejb3;
|
| import javax.ejb.Stateless;
|
| @Stateless
| public class HelloServiceBean implements HelloService {
| public String hello(String name) {
| return "Hello " + name + " ";
| }
| }
This EJB is correctly deployed in JBoss and I can call it form my web module.
My second EJB Session Stateless which use EJB Entity don't run well :
Contact.java :
package com.test.jboss.ejb3;
|
| import javax.persistence.Entity;
| import javax.persistence.GeneratedValue;
| import javax.persistence.GenerationType;
| import javax.persistence.Id;
| import javax.persistence.Table;
|
| @Entity
| @Table(name="contact")
| public class Contact {
| @Id
| @GeneratedValue(strategy=GenerationType.AUTO)
| private int id;
|
| private String name;
|
| public int getId() {
| return id;
| }
|
| public void setId(int id) {
| this.id = id;
| }
|
| public String getName() {
| return name;
| }
|
| public void setName(String name) {
| this.name = name;
| }
| }
|
ContactService.java :
package com.test.jboss.ejb3;
|
| import java.util.Collection;
|
| import javax.ejb.Local;
|
| @Local
| public interface ContactService {
| public Collection<Contact> findAllContact();
| }
ContactServiceBean.java :
package com.test.jboss.ejb3;
|
| import java.util.Collection;
|
| import javax.ejb.Stateless;
| import javax.persistence.EntityManager;
| import javax.persistence.PersistenceContext;
|
| @Stateless
| public class ContactServiceBean implements ContactService {
| @PersistenceContext(unitName = "testdb")
| protected EntityManager em;
|
| @SuppressWarnings("unchecked")
| public Collection<Contact> findAllContact() {
| return em.createQuery("SELECT c FROM Contact c").getResultList();
| }
| }
META-INF/persistance.xml :
<?xml version="1.0" encoding="UTF-8"?>
| <persistence>
| <persistence-unit name="testdb">
| <jta-data-source>java:/DefaultDS</jta-data-source>
| <properties>
| <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
| <property name="hibernate.show_sql" value="true"/>
| <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
| </properties>
| </persistence-unit>
| </persistence>
This EJB is not correctly loaded in JBoss :
16:07:27,225 INFO [EARDeployer] Init J2EE application: file:/D:/Program Files/jboss-4.0.5.GA/server/default/deploy/test-jboss-ear.ear
| 16:07:27,444 INFO [Ejb3Deployment] EJB3 deployment time took: 15
| 16:07:27,460 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:ear=test-jboss-ear.ear,jar=test-jboss-ejb.jar,name=ContactServiceBean,service=EJB3 with dependencies:
| 16:07:27,460 INFO [JmxKernelAbstraction] persistence.units:unitName=testdb
| 16:07:27,460 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:ear=test-jboss-ear.ear,jar=test-jboss-ejb.jar,name=HelloServiceBean,service=EJB3 with dependencies:
| 16:07:27,475 INFO [EJBContainer] STARTED EJB: com.test.jboss.ejb3.HelloServiceBean ejbName: HelloServiceBean
| 16:07:27,475 INFO [EJB3Deployer] Deployed: file:/D:/Program Files/jboss-4.0.5.GA/server/default/tmp/deploy/tmp65187test-jboss-ear.ear-contents/test-jboss-ejb.jar
| 16:07:27,491 INFO [TomcatDeployer] deploy, ctxPath=/test-jboss-web, warUrl=.../tmp/deploy/tmp65187test-jboss-ear.ear-contents/test-jboss-web-exp.war/
| 16:07:27,694 INFO [EARDeployer] Started J2EE application: file:/D:/Program Files/jboss-4.0.5.GA/server/default/deploy/test-jboss-ear.ear
| 16:07:27,694 ERROR [URLDeploymentScanner] Incomplete Deployment listing:
|
| --- MBeans waiting for other MBeans ---
| ObjectName: jboss.j2ee:ear=test-jboss-ear.ear,jar=test-jboss-ejb.jar,name=ContactServiceBean,service=EJB3
| State: NOTYETINSTALLED
| I Depend On:
| persistence.units:unitName=testdb
|
| --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
| ObjectName: persistence.units:unitName=testdb
| State: NOTYETINSTALLED
| Depends On Me:
| jboss.j2ee:ear=test-jboss-ear.ear,jar=test-jboss-ejb.jar,name=ContactServiceBean,service=EJB3
|
Moreover, my web module cannot call the EJB because the following exception is throwed : javax.naming.NameNotFoundException: ContactServiceBean not bound.
Anybody can explain me the trouble please ?
Thanks,
Regards,
Zero
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4008881#4008881
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4008881
17 years, 10 months
[EJB 3.0] - JPQL WHERE syntax works for SELECT but not DELETE
by timotten
I'm experiencing some unexpected behavior when I try to delete an entity in which a JPQL WHERE condition behaves as expected for a SELECT query but not for a DELETE query.
Background: I'm using JBoss 4.0.5.GA in the ejb3 configuration with a MySQL 5.0 data source. This problem involves three entities and one stateless session bean. The entities are:
| @Entity
| public class Account implements Serializable {
| @Id
| @GeneratedValue(strategy = GenerationType.AUTO)
| private Long id;
|
| @OneToOne(cascade = CascadeType.ALL,fetch=FetchType.EAGER)
| @PrimaryKeyJoinColumn
| private Profile profile;
|
| ...
| }
|
| @Entity
| public class Profile {
| @Id
| @GeneratedValue(strategy = GenerationType.AUTO)
| private Long id;
|
| @OneToOne(cascade=CascadeType.ALL, fetch=FetchType.EAGER, mappedBy="profile")
| private Account account;
|
| @Column(unique=true)
| private String email;
|
| ...
| }
|
| @Entity
| @Inheritance(strategy=InheritanceType.JOINED)
| public class Notification implements Serializable {
|
| @Id
| @GeneratedValue(strategy = GenerationType.AUTO)
| private Long id;
|
| @ManyToOne
| private Account recipient;
|
| ...
| }
|
The problem comes when I try to remove an instance of Notification while applying a filter based on part of the user's login credential (specifically, the email address). The following three code snippets were used in the stateless session bean:
| /* Version 1 - Select query with email; then remove */
| Notification n = (Notification) em.createQuery("SELECT object(n) " +
| "FROM Notification n " +
| "WHERE n.id=:id AND n.recipient.profile.email=:email "
| )
| .setParameter("id", id)
| .setParameter("email", email)
| .getSingleResult();
| em.remove(n);
|
| /* Version 2 - Delete query with Email */
| int res= em.createQuery("DELETE " +
| "FROM Notification n " +
| "WHERE n.id=:id AND n.recipient.profile.email=:email "
| )
| .setParameter("id", id)
| .setParameter("email", email)
| .executeUpdate();
|
| /* Version 3 - Delete query with Id */
| int res= em.createQuery("DELETE " +
| "FROM Notification n " +
| "WHERE n.id=:id AND n.recipient.profile.id=:pid"
| )
| .setParameter("id", id)
| .setParameter("pid", profileId)
| .executeUpdate();
|
Versions 1 and 3 both work. Version 2 fails with a multi-part exception, the root of which is:
| Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'email' in 'where clause'
| at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
| at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
| at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
| at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
| at com.mysql.jdbc.Connection.execSQL(Connection.java:3176)
| at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1153)
| at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1404)
| at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1318)
| at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1303)
| at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:251)
| at org.hibernate.hql.ast.exec.MultiTableDeleteExecutor.execute(MultiTableDeleteExecutor.java:93)
| ... 64 more
|
|
The exception seems strange, however, because the email column does exist on the Profile table and because the same WHERE syntax works for the SELECT.
Obviously, I can work around this ("Don't use version 2!"), but I'd like to figure out if this is a bug[1] or if I'm doing something wrong.
[1] I checked Jira for bugs relating to "executeUpdate" and "MultiTableDeleteExecutor", but I didn't spot anything relevent.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4008875#4008875
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4008875
17 years, 10 months