[EJB 3.0] - EJB 3.0 AND JBOSS 4.0.4 G.A
by priyavijayan1
Hi,
I am having a problem with EJB 3.0 . I am using
EJB-3.0_RC9-FD
jboss-4.0.4.GA
jdk 1.5
ant 1.6.5
I am using the hypersonic database of jboss and I want to create two tables in the database Department and Emplyee.
The code for client.java
package com.abcd.EJB3.application;
import com.infosys.EJB3.application.FacadeRemote;
import javax.naming.InitialContext;
import java.sql.Timestamp;
public class client
{
public static void main(String[] args)
{
try
{
InitialContext ctx = new InitialContext();
FacadeRemote lFacadeRemote = (FacadeRemote) ctx.lookup(FacadeRemote.class.getName());
lFacadeRemote.createDepartment("Finance");
lFacadeRemote.createDepartment("Administration");
lFacadeRemote.createDepartment("Sales");
lFacadeRemote.assignEmployeeToDepartment(new Long(1),"Brijesh",31,"M");
lFacadeRemote.assignEmployeeToDepartment(new Long(1),"xxxx",31,"M");
lFacadeRemote.assignEmployeeToDepartment(new Long(2),"yyyy",31,"M");
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
The code for department.java
package com.abcd.EJB3.application;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@Table(name = "DEPARTMENT")
public class Department implements java.io.Serializable
{
private Long id;
private String lsName;
private Collection lEmployees;
//@Id(generate = GeneratorType.AUTO)
@Id @GeneratedValue(strategy=GenerationType.AUTO)
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
@Column(name = "NAME")
public String getName()
{
return lsName;
}
public void setName(String asName)
{
this.lsName = asName;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy="department")
public Collection getEmployees()
{
return lEmployees;
}
public void setEmployees(Collection aEmployees)
{
this.lEmployees = aEmployees;
}
public void addEmployee(String asName,int aiAge, String asSex)
{
if(lEmployees== null)
lEmployees = new ArrayList();
Employee lEmployee = new Employee();
lEmployee.setName(asName);
lEmployee.setAge(aiAge);
lEmployee.setSex(asSex);
lEmployee.setDepartment(this);
lEmployees.add(lEmployee);
setEmployees(lEmployees);
}
}
the code for Employee.java
package com.abcd.EJB3.application;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Column;
import javax.persistence.Table;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.CascadeType;
import javax.persistence.PostPersist;
import java.util.Set;
//@Entity
public class Employee implements java.io.Serializable
{
private Long id;
private String lsName;
private int liAge;
private String lsSex;
private Department department;
public Employee()
{
}
//@Id(generate = GeneratorType.IDENTITY)
// @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
// @Column(name = "NAME")
public String getName()
{
return lsName;
}
public void setName(String asName)
{
this.lsName = asName;
}
// @Column(name = "AGE")
public int getAge()
{
return liAge;
}
public void setAge(int liAge)
{
this.liAge = liAge;
}
// @Column(name = "SEX")
public String getSex()
{
return lsSex;
}
public void setSex(String lsSex)
{
this.lsSex = lsSex;
}
// @ManyToOne
// @JoinColumn(name="DEPARTMENT_ID")
public Department getDepartment()
{
return department;
}
public void setDepartment(Department aDepartment)
{
this.department = aDepartment;
}
// @PostPersist
public void samplePostPersist()
{
System.out.println("Added Employee having name = "+ this.getName() +" and Age = "+ this.getAge());
}
}
code for FacadeBean
package com.abcd.EJB3.application;
import javax.ejb.Stateless;
import javax.ejb.Remote;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import com.infosys.EJB3.application.Department;
import com.infosys.EJB3.application.Employee;
import java.util.Set;
@Stateless
public class FacadeBean implements FacadeRemote
{
@PersistenceContext
private EntityManager manager;
public void createDepartment(String deptName)
{
Department department = new Department();
department.setName(deptName);
manager.persist(department);
}
public void assignEmployeeToDepartment(Long id, String name, int age, String sex)
{
Department department = searchDepartment(id);
department.addEmployee(name, age, sex);
manager.persist(department);
}
public Department searchDepartment(Long id)
{
return manager.find(Department.class,id);
}
}
code for FacadeRemote
package com.abcd.EJB3.application;
import javax.ejb.Remote;
@Remote
public interface FacadeRemote
{
public void createDepartment(String deptName);
public Department searchDepartment(Long id);
public void assignEmployeeToDepartment(Long id, String name, int age, String sex);
}
now I have compiled the code and deployed it. But when I try to run the code I get the following error:
NameNotFoundException ----- FacadeRemote not bound.
I think its something related to JNDI binding.. but here since I am using EJB 3.0, i dont have to use ejb-jar.xml, but then how does this happens?? what should I do... Please help....
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3996098#3996098
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3996098
19 years, 4 months
[Clustering/JBoss] - Re: Running multiple instances of JBoss on one machine: need
by sjsaunders
This is the change to ConfiguringMultipleJBossInstancesOnOneMachine that I am asking about:
Difference between version 34 and version 33:
Line 45 was replaced by lines 45-46
- If you intend to launch multiple JBoss instances on the same machine and have them form a cluster, you might write some kind of script to launch the two instances. It is a good practice to add some kind of pause in your script between the launch of the first instance and the second. 10 to 20 seconds is good.
+ We highly recommend against configurating a cluster using the Service Binding Manager. Instead bind each server instance to a separate ip address (or DNS alias) (bound to the same NIC or not):\\
+ __ e.g. $run.sh -c node1 -b 192.168.4.1 (or -b node1.mycluster.acme.com)
Removed line 47
- This is because if both instances are launched simultaneously, they both may decide they are the JGroups coordinator. At this point, you will have two independent clusters of one node each. If this happens, both nodes may begin to start HASingleton services, such as HA-JMS. A few seconds later, the two nodes will discover each other and the two clusters will merge. One of the nodes will no longer be coordinator, and the HASingleton services will be stopped. Stopping a service that's in the middle of starting does not always go cleanly.
Removed line 49
- By putting a pause in your startup script, it gives the first node a chance to become coordinator before the second node starts. The second node will then cleanly join the cluster, and no HASingleton services will be started on it.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3996094#3996094
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3996094
19 years, 4 months
[EJB/JBoss] - problem with jboss-EJB-3.0_RC9-FD and jboss-4.0.4.GA
by priyavijayan1
Hi,
I am having a problem with EJB 3.0 . I am using
EJB-3.0_RC9-FD
jboss-4.0.4.GA
jdk 1.5
ant 1.6.5
I am using the hypersonic database of jboss and I want to create two tables in the database Department and Emplyee.
The code for client.java
package com.abcd.EJB3.application;
import com.infosys.EJB3.application.FacadeRemote;
import javax.naming.InitialContext;
import java.sql.Timestamp;
public class client
{
public static void main(String[] args)
{
try
{
InitialContext ctx = new InitialContext();
FacadeRemote lFacadeRemote = (FacadeRemote) ctx.lookup(FacadeRemote.class.getName());
lFacadeRemote.createDepartment("Finance");
lFacadeRemote.createDepartment("Administration");
lFacadeRemote.createDepartment("Sales");
lFacadeRemote.assignEmployeeToDepartment(new Long(1),"Brijesh",31,"M");
lFacadeRemote.assignEmployeeToDepartment(new Long(1),"xxxx",31,"M");
lFacadeRemote.assignEmployeeToDepartment(new Long(2),"yyyy",31,"M");
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
The code for department.java
package com.abcd.EJB3.application;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@Table(name = "DEPARTMENT")
public class Department implements java.io.Serializable
{
private Long id;
private String lsName;
private Collection lEmployees;
//@Id(generate = GeneratorType.AUTO)
@Id @GeneratedValue(strategy=GenerationType.AUTO)
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
@Column(name = "NAME")
public String getName()
{
return lsName;
}
public void setName(String asName)
{
this.lsName = asName;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy="department")
public Collection getEmployees()
{
return lEmployees;
}
public void setEmployees(Collection aEmployees)
{
this.lEmployees = aEmployees;
}
public void addEmployee(String asName,int aiAge, String asSex)
{
if(lEmployees== null)
lEmployees = new ArrayList();
Employee lEmployee = new Employee();
lEmployee.setName(asName);
lEmployee.setAge(aiAge);
lEmployee.setSex(asSex);
lEmployee.setDepartment(this);
lEmployees.add(lEmployee);
setEmployees(lEmployees);
}
}
the code for Employee.java
package com.abcd.EJB3.application;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Column;
import javax.persistence.Table;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.CascadeType;
import javax.persistence.PostPersist;
import java.util.Set;
//@Entity
public class Employee implements java.io.Serializable
{
private Long id;
private String lsName;
private int liAge;
private String lsSex;
private Department department;
public Employee()
{
}
//@Id(generate = GeneratorType.IDENTITY)
// @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
// @Column(name = "NAME")
public String getName()
{
return lsName;
}
public void setName(String asName)
{
this.lsName = asName;
}
// @Column(name = "AGE")
public int getAge()
{
return liAge;
}
public void setAge(int liAge)
{
this.liAge = liAge;
}
// @Column(name = "SEX")
public String getSex()
{
return lsSex;
}
public void setSex(String lsSex)
{
this.lsSex = lsSex;
}
// @ManyToOne
// @JoinColumn(name="DEPARTMENT_ID")
public Department getDepartment()
{
return department;
}
public void setDepartment(Department aDepartment)
{
this.department = aDepartment;
}
// @PostPersist
public void samplePostPersist()
{
System.out.println("Added Employee having name = "+ this.getName() +" and Age = "+ this.getAge());
}
}
code for FacadeBean
package com.abcd.EJB3.application;
import javax.ejb.Stateless;
import javax.ejb.Remote;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import com.infosys.EJB3.application.Department;
import com.infosys.EJB3.application.Employee;
import java.util.Set;
@Stateless
public class FacadeBean implements FacadeRemote
{
@PersistenceContext
private EntityManager manager;
public void createDepartment(String deptName)
{
Department department = new Department();
department.setName(deptName);
manager.persist(department);
}
public void assignEmployeeToDepartment(Long id, String name, int age, String sex)
{
Department department = searchDepartment(id);
department.addEmployee(name, age, sex);
manager.persist(department);
}
public Department searchDepartment(Long id)
{
return manager.find(Department.class,id);
}
}
code for FacadeRemote
package com.abcd.EJB3.application;
import javax.ejb.Remote;
@Remote
public interface FacadeRemote
{
public void createDepartment(String deptName);
public Department searchDepartment(Long id);
public void assignEmployeeToDepartment(Long id, String name, int age, String sex);
}
now I have compiled the code and deployed it. But when I try to run the code I get the following error:
NameNotFoundException ----- FacadeRemote not bound.
I think its something related to JNDI binding.. but here since I am using EJB 3.0, i dont have to use ejb-jar.xml, but then how does this happens?? what should I do... Please help....
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3996092#3996092
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3996092
19 years, 4 months
[Persistence, JBoss/CMP, Hibernate, Database] - Re: Hibernate loads all entities on manager.merge()
by murtuza52
I found the culprit. For those who have performance related issue, this might be one of the reasons. The culprit here was the use of FetchType.EAGER. This might be because of "load-before-update" strategy hibernate uses to check the columns have changed. Over use of EAGER means its going to load every related entities in memory and therefore performance is effected.
Make all relations LAZY except for those that are absolutely required. You can easily debug and find out if the application server is working hard to synchronize with the database by using Use tags
| <property name="hibernate.show_sql" value="true"/>
| <property name="hibernate.use_sql_comments" value="true"/>
|
in persistence.xml file. This will show you what is happening in background and you can find out what entities get loaded will persisting or merging.
I hope hibernate or jboss comes up with better strategy to synchronize the data. This doesn't seems to be effecting the performance with server like GlassFish or JDO framework. They have different algorithm that performans more efficients.
Feedback are welcomed to improve the performance further.
Murtuza
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3996091#3996091
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3996091
19 years, 4 months