[EJB 3.0] - Web Page Having Trouble Connecting to EJB 3.0 Enity
by kurzweil4
I have an application with a Model and a View project. The bean in the View project is having trouble finding the EJB Enity in the Model project. The binding DepartmentsBean.departments is failing with this error:
javax.el.ELException: javax.faces.el.EvaluationException: javax.el.ELException: Error reading 'departments' on type ice.data.table.view.DepartmentsBean
I had the EXACT same error when I was deploying to OC4J, but the problem was that my Model project was not deployed as an EJB Jar. That is not the problem in this case since I am now using en EJB Jar.
Also, I have tested my DB connection with a plain JSP manually querying a table in the DB, so I know my connection configuration is good.
This is my persistence.xml:
<?xml version="1.0" encoding="windows-1252" ?>
| <persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
| version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
| <persistence-unit name="Model">
| <jta-data-source>java:/hr</jta-data-source>
| <class>ice.data.table.model.Departments</class>
| <class>ice.data.table.model.DepPublicFacade</class>
| <class>ice.data.table.model.DepPublicFacadeLocal</class>
| <class>ice.data.table.model.DepPublicFacadeBean</class>
| </persistence-unit>
| </persistence>
|
This is my entity:
| @Entity
| @NamedQuery( name = "Departments.findAll",
| query = "select o from Departments o" )
| public class Departments implements Serializable
| {
| @Id
| @Column( name="DEPARTMENT_ID", nullable = false )
| private Long departmentId;
| @Column( name="DEPARTMENT_NAME", nullable = false )
| private String departmentName;
| @Column( name="LOCATION_ID" )
| private Long locationId;
| @Column( name="MANAGER_ID" )
| private Long managerId;
|
| public Departments()
| {
| }
|
| public Long getDepartmentId()
| {
| return departmentId;
| }
|
| public void setDepartmentId( Long departmentId )
| {
| this.departmentId = departmentId;
| }
|
| public String getDepartmentName()
| {
| return departmentName;
| }
|
| public void setDepartmentName( String departmentName )
| {
| this.departmentName = departmentName;
| }
|
| public Long getLocationId()
| {
| return locationId;
| }
|
| public void setLocationId( Long locationId )
| {
| this.locationId = locationId;
| }
|
| public Long getManagerId()
| {
| return managerId;
| }
|
| public void setManagerId( Long managerId )
| {
| this.managerId = managerId;
| }
| }
|
This is my facade:
| @Stateless( name="DepPublicFacade" )
| public class DepPublicFacadeBean implements DepPublicFacade, DepPublicFacadeLocal
| {
| @PersistenceContext( unitName="Model" )
| private EntityManager em;
|
| public DepPublicFacadeBean()
| {
| }
|
| public Object mergeEntity( Object entity )
| {
| return em.merge(entity);
| }
|
| public Object persistEntity( Object entity )
| {
| em.persist(entity);
| return entity;
| }
|
| /** <code>select o from Departments o</code> */
| public List<Departments> queryDepartmentsFindAll()
| {
| return em.createNamedQuery("Departments.findAll").getResultList();
| }
|
| public void removeDepartments( Departments departments )
| {
| departments = em.find(Departments.class, departments.getDepartmentId());
| em.remove(departments);
| }
| }
|
This is my bean from the View project:
| public class DepartmentsBean
| {
| private DepPublicFacade model;
|
| public DepartmentsBean()
| {
| try
| {
| final Context context = getInitialContext();
| model = (DepPublicFacade)context.lookup("DepPublicFacade");
| }
| catch (Exception ex)
| {
| ex.printStackTrace();
| }
| }
|
| public List getDepartments()
| {
| return model.queryDepartmentsFindAll();
| }
|
| private static Context getInitialContext() throws NamingException
| {
| // Get InitialContext for Embedded OC4J
| // The embedded server must be running for lookups to succeed.
| return new InitialContext();
| }
| }
|
Any help or pointers to information would be appreciated. I am at a loss here.
Thanks,
Kurzweil4
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4070906#4070906
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4070906
18Â years, 8Â months
[Persistence, JBoss/CMP, Hibernate, Database] - Getting a session from entityManager
by mladen.babic
Hi ,
I 've tried to use query by example.Problem is thet I get error when I try to get session.This is fragment of my code:
| public List<DistributorEntity> findDistributors(String name,BigDecimal time,BigDecimal costs,String account){
| DistributorEntity newDistributor=new DistributorEntity();
| newDistributor.setName(name);
| newDistributor.setDeliveryTime(time.intValue());
| newDistributor.setDeliveryCosts(costs);
| newDistributor.setAccount(account);
| Session session = (Session)entityManager.getDelegate();
| Example distributorExample=Example.create(newDistributor)
| .ignoreCase()
| .excludeZeroes()
| .enableLike();
| List list = session.createCriteria(DistributorEntity.class)
| .add(distributorExample).list();
| return list;
|
In debug mode I have found that problem is in entityManager. getDelegate().It return null.How will i solve a problem?
Best regards,
mb
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4070901#4070901
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4070901
18Â years, 8Â months
[JBoss Seam] - EntityManager is null??
by mladen.babic
Hi ,
I've tried to use entityQuery in my app but it trows me error:
| SEVERE: Error Rendering View[/order/distributors/distributors.xhtml]
| java.lang.IllegalStateException: entityManager is null
| at org.jboss.seam.framework.EntityQuery.validate(EntityQuery.java:31)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
| at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
| at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
| at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:38)
| at org.jboss.seam.util.Work.workInTransaction(Work.java:39)
| at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:32)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
| at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
| at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java
My components.xml file looks :
|
| <core:managed-persistence-context name="entityManager"
| auto-create="true"
| persistence-unit-jndi-name="java:/private.eOrderEntityManagerFactory" />
|
| . . .
|
| <framework:entity-query name="distributors"
| ejbql="select d from DistributorEntity d"
| order="name"/>
|
|
On page i get "EntityManager is null".What is the problem? I created project with seam-gen.
Best regards,
mb
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4070900#4070900
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4070900
18Â years, 8Â months
[JBoss Seam] - nested conversations and parent objects
by pdpantages
Hello Forum,
I am using Seam 1.2.1.GA
I am using nested conversations to edit entries in a table.
The editor is in a nested conversation, launched from a long running conversation.
The conversation is started with s:link+propagation="nest"
The editor injects the table bean with
@In
ServiceTableLocal serviceMgmt;
(The serviceMgmt bean contains an @Datamodel which is used to render the table).
When the edit is applied, I want to refresh the tablebean, which I do by calling
serviceMgmt.refresh();
This is done in the context of the nested conversation, in the editor.apply() method.
The odd thing is, everything works properly.... The documentation clearly states that the parent/outer conversation objects are "readl-only" in the nested conversation.
If I remove the refresh call, I verifed that the table is not updated- i.e., there is no "hidden mechanism" helping me out.
I expected the refresh to have no effect, as per the docs. Is this new behaviour for 1.2.1, or a bug?
I used to call
Conversation.instance().end();
Conversation.instance().pop();
before the refresh, so that the latter call was done in the parent/outer conversation.
I have switched to using @End as this technique was causing occasional "can't find stateful bean" problems. I expecetd my refesh to stop working, but it didn't....
Anyone have any insights into this behaviour?
Thanks, PdP
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4070895#4070895
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4070895
18Â years, 8Â months