[EJB 3.0] - Re: Cannot remove entites used in relationships
by valatharv
I need help while deleting child entity, please suggest how can I handle it. I tried posting in seam forum but that is not the right place..
I am stuck and need help... :( new to this...
Entity Overview :
-Project entity can have multiple QuantExperiments.
-QuantExperiment entity can have multiple Reagents and
-Reagent entity can have multiple Treatments.
As per functionalities user can CREATE, UPDATE or DELETE any entity from UI.
I created few Treatments for Reagents and few reagents for experiments, etc.
Now, when I try to delete only ONE treatment from Treatment home it gives exception as :
----------------------
Caused by: javax.persistence.EntityNotFoundException: deleted entity passed to persist: [com.entity.Treatment#]
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:613)
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:299)
at org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:90)
at org.jboss.seam.framework.EntityHome.remove(EntityHome.java:108)
at com.TreatmentHome.remove(TreatmentHome.java:86)----------------------
I think it is issue with CascadeType but not able to figure out. "TreatmentHome.remove()" is called while (deleting)
I tried using various combinations for CascadeType like using but no success.
"CascadeType.MERGE,CascadeType.REFRESH,CascadeType.REMOVE" on Reagent.getTreatment() and Treatment.getReagent()
Project entity :
| ----------------
| public class Project
| implements Equals, HashCode, ToString{
| ......
|
| protected List<QuantExperiment> quantExperiment;
|
| @OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY, mappedBy="project")
| public List<QuantExperiment> getQuantExperiment() {
| if (quantExperiment == null) {
| quantExperiment = new ArrayList<QuantExperiment>();
| }
| return this.quantExperiment;
| }
|
| public void setQuantExperiment(List<QuantExperiment> quantExperiment) {
| for(QuantExperiment q : quantExperiment){
| q.setProject(this);
| }
| this.quantExperiment = quantExperiment;
| }
QuantExperiment entity :
| ------------------------
| public class QuantExperiment
| implements Equals, HashCode, ToString {
| ......
| protected List<Reagent> reagent;
| protected Project project;
|
| @OneToMany(cascade = {CascadeType.ALL}, , fetch = FetchType.LAZY, mappedBy="quantExperiment")
| public List<Reagent> getReagent() {
| if (reagent == null) {
| reagent = new ArrayList<Reagent>();
| }
| return this.reagent;
| }
|
| public void setReagent(List<Reagent> reagent) {
| for(Reagent r : reagent){
| r.setQuantExperiment(this);
| }
| this.reagent = reagent;
| }
|
| @ManyToOne(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY, optional=false)
| public Project getProject() {
| return project;
| }
| public void setProject(Project project) {
| this.project = project;
| }
Reagent entity :
| ----------------
| public class Reagent
| implements Equals, HashCode, ToString {
| ....
| protected List<Treatment> treatment;
| protected QuantExperiment quantExperiment;
|
| @OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY, mappedBy="reagent")
| public List<Treatment> getTreatment() {
| if (treatment == null) {
| treatment = new ArrayList<Treatment>();
| }
| return this.treatment;
| }
| public void setTreatment(List<Treatment> treatment) {
| for(Treatment t : treatment){
| t.setReagent(this);
| }
| this.treatment = treatment;
| }
|
| @ManyToOne(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY, optional=false)
| public QuantExperiment getQuantExperiment() {
| return quantExperiment;
| }
| public void setQuantExperiment(QuantExperiment quantExperiment) {
| this.quantExperiment = quantExperiment;
| }
Treatment entity :
| ------------------
| public class Treatment
| implements Equals, HashCode, ToString {
| ......
| protected Reagent reagent;
| @ManyToOne(cascade = {CascadeType.ALL},optional=false)
| public Reagent getReagent() {
| return reagent;
| }
| public void setReagent(Reagent reagent) {
| this.reagent = reagent;
| }
TreatmentHome.java
| ------------------
| @Name("treatmentHome")
| public class TreatmentHome extends EntityHome<Treatment> {
|
| @In(create = true)
| ReagentHome reagentHome;
| .....
|
| @Override
| public String remove(){
| return super.remove();
| }
| ....
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4193866#4193866
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4193866
17 years, 4 months
[Security & JAAS/JBoss] - Using JAAS with Thread Pools
by leobaz2
My application consists of 2 EARs. One EAR has the web application and presentation logic. The other EAR consists of secured session EJBs.
In the Web App EAR I defined a ServletContextListener that will authenticate itself with the EAR containing the secured EJBs. I am doing this using the ClientLoginModule. The EAR with the secured EJBs contains a SAR that defines a custom login module where I also create a custom Principal.
My problem is that when a request comes in from the web application and that thread tries to access the secured EJBs, it fails saying I am unauthorized to do so. Does anyone know how to associate the calling thread with the security context created in the ServletContextListener?
During the JAAS authentication, I am storing the Subject returned from the login method. I have tried Subject.doAs but it doesn't work. I am porting my application from WebLogic where it works fine using the Subject.runAs provided by a WebLogic library.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4193853#4193853
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4193853
17 years, 4 months
[Beginners Corner] - problem trying to create new bean (EJB2.0)
by MikePhoenix
I'm trying to create a new entity bean for an existing application. When I deploy I get the following error:
anonymous wrote : org.jboss.deployment.DeploymentException: Field changeDate in prim-key-class must be of the same type.
New table sql
CREATE TABLE `projecthistory` (
| `ProjectId` int(11) NOT NULL default '0',
| `ChangeDate` datetime NOT NULL,
| `UserID` varchar(50) NOT NULL,
| `Status` int(11) NOT NULL default '0',
| PRIMARY KEY (`ProjectId`, `ChangeDate`),
| KEY `projecthistory_ProjectID_FK` (`ProjectId`),
| CONSTRAINT `projecthistory_ProjectID_FK` FOREIGN KEY (`ProjectId`) REFERENCES `projects` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
| );
prim-key in ejb-jar.xml
<prim-key-class>lingonet.projecthistory.ProjectHistoryKey</prim-key-class>
The key class
public class ProjectHistoryKey {
| public Integer projectID;
| public Date changeDate;
|
| public ProjectHistoryKey (Integer projectID, Date changeDate) {
| this.projectID = projectID;
| this.changeDate = changeDate;
| }
| }
|
I am using java.util.date in my java code, which works for other beans where the date isn't a primary key? Do I need to use java.sql.date or is there just a problem using dates in primary keys or something else entirely? Some guidance here would be appreciated.
Mike
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4193849#4193849
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4193849
17 years, 4 months
[EJB/JBoss] - problem with new bean I'm creating (EJB2.0)
by MikePhoenix
I'm trying to create a new entity bean for an existing application. When I deploy I get the following error:
anonymous wrote : org.jboss.deployment.DeploymentException: Field changeDate in prim-key-class must be of the same type.
New table sql
CREATE TABLE `projecthistory` (
| `ProjectId` int(11) NOT NULL default '0',
| `ChangeDate` datetime NOT NULL,
| `UserID` varchar(50) NOT NULL,
| `Status` int(11) NOT NULL default '0',
| PRIMARY KEY (`ProjectId`, `ChangeDate`),
| KEY `projecthistory_ProjectID_FK` (`ProjectId`),
| CONSTRAINT `projecthistory_ProjectID_FK` FOREIGN KEY (`ProjectId`) REFERENCES `projects` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
| );
prim-key in ejb-jar.xml
<prim-key-class>lingonet.projecthistory.ProjectHistoryKey</prim-key-class>
The key class
public class ProjectHistoryKey {
| public Integer projectID;
| public Date changeDate;
|
| public ProjectHistoryKey (Integer projectID, Date changeDate) {
| this.projectID = projectID;
| this.changeDate = changeDate;
| }
| }
|
I am using java.util.date in my java code, which works for other beans where the date isn't a primary key? Do I need to use java.sql.date or is there just a problem using dates in primary keys or something else entirely? Some guidance here would be appreciated.
Mike
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4193845#4193845
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4193845
17 years, 4 months
[Installation, Configuration & DEPLOYMENT] - Re: Performance parameters for JBOSS
by PeterJ
Use the JMX Console (http://localhost:8080/jmx-console). It lists all of the MBeans registered in JBossAS. Several of them contain performance information. Here are some examples, there are others:
For a data source named xxx, the following MBean provides information on the number of connections:
jboss.jca:name=xxx,service=ManagedConnectionPool
For HTTP connections, you can see the thread counts in
jboss.web:type=ThreadPool,name=http-99.99.99.99-8080
where 99.99.99.99 is your IP address.
For servlets, you can see processing times and number of requests in
jboss.web:j2eeType=Servlet,J2EEserver=none,J2EEApplication=xxx,WebModule=//hostname/xxx,name=XXX
For EJBs, you can see similar information in the stats attribute for
jboss.management.local:J2EEServer=local,j2eeType=bean-type,J2EEApplication=ear-file,EJBModule=jar-file,name=ejb-name
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4193837#4193837
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4193837
17 years, 4 months