Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8051099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:13:54+00:00 2026-06-05T07:13:54+00:00

am using jsf 2.0 + primefaces 3.2 + EJB 2.0 + JPA 2.0 .

  • 0

am using jsf 2.0 + primefaces 3.2 + EJB 2.0 + JPA 2.0 .
hi everyone, when i try to affect a new student to a class the system raises an error message which is trasaction abored.
my entity code : ClasseHasEtudiant

public class ClasseHasEtudiant implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
protected ClasseHasEtudiantPK classeHasEtudiantPK;
@JoinColumn(name = "Etudiant_id", referencedColumnName = "id", insertable = false, updatable = false)
@ManyToOne(optional = false)
private Etudiant etudiant;
@JoinColumn(name = "Classe_id", referencedColumnName = "id", insertable = false, updatable = false)
@ManyToOne(optional = false)
private Classe classe;

public ClasseHasEtudiant() {
}

public ClasseHasEtudiant(ClasseHasEtudiantPK classeHasEtudiantPK) {
    this.classeHasEtudiantPK = classeHasEtudiantPK;
}

public ClasseHasEtudiant(int classeid, int etudiantid) {
    this.classeHasEtudiantPK = new ClasseHasEtudiantPK(classeid, etudiantid);
}

public ClasseHasEtudiantPK getClasseHasEtudiantPK() {
    return classeHasEtudiantPK;
}

public void setClasseHasEtudiantPK(ClasseHasEtudiantPK classeHasEtudiantPK) {
    this.classeHasEtudiantPK = classeHasEtudiantPK;
}

public Etudiant getEtudiant() {
    return etudiant;
}

public void setEtudiant(Etudiant etudiant) {
    this.etudiant = etudiant;
}

public Classe getClasse() {
    return classe;
}

public void setClasse(Classe classe) {
    this.classe = classe;
}

@Override
public int hashCode() {
    int hash = 0;
    hash += (classeHasEtudiantPK != null ? classeHasEtudiantPK.hashCode() : 0);
    return hash;
}

@Override
public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof ClasseHasEtudiant)) {
        return false;
    }
    ClasseHasEtudiant other = (ClasseHasEtudiant) object;
    if ((this.classeHasEtudiantPK == null && other.classeHasEtudiantPK != null) || (this.classeHasEtudiantPK != null && !this.classeHasEtudiantPK.equals(other.classeHasEtudiantPK))) {
        return false;
    }
    return true;
}

@Override
public String toString() {
    return "dossierEtudiants.entities.ClasseHasEtudiant[ classeHasEtudiantPK=" + classeHasEtudiantPK + " ]";
}

}

code of entity ClasseHasEtudiantPK

@Embeddable
public class ClasseHasEtudiantPK implements Serializable {
@Basic(optional = false)
@NotNull
@Column(name = "Classe_id")
private int classeid;
@Basic(optional = false)
@NotNull
@Column(name = "Etudiant_id")
private int etudiantid;

public ClasseHasEtudiantPK() {
}

public ClasseHasEtudiantPK(int classeid, int etudiantid) {
    this.classeid = classeid;
    this.etudiantid = etudiantid;
}

public int getClasseid() {
    return classeid;
}

public void setClasseid(int classeid) {
    this.classeid = classeid;
}

public int getEtudiantid() {
    return etudiantid;
}

public void setEtudiantid(int etudiantid) {
    this.etudiantid = etudiantid;
}

@Override
public int hashCode() {
    int hash = 0;
    hash += (int) classeid;
    hash += (int) etudiantid;
    return hash;
}

@Override
public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof ClasseHasEtudiantPK)) {
        return false;
    }
    ClasseHasEtudiantPK other = (ClasseHasEtudiantPK) object;
    if (this.classeid != other.classeid) {
        return false;
    }
    if (this.etudiantid != other.etudiantid) {
        return false;
    }
    return true;
}

@Override
public String toString() {
    return "dossierEtudiants.entities.ClasseHasEtudiantPK[ classeid=" + classeid + ", etudiantid=" + etudiantid + " ]";
}

}

this is my .xhtml code :

<ui:define name="content">
        <h:panelGroup id="messagePanel" layout="block">
            <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
        </h:panelGroup>
        <h:form>
            <h:panelGrid columns="2">
                <h:outputLabel value="#{bundle.CreateClasseHasEtudiantLabel_etudiant}" for="etudiant" />
                <h:selectOneMenu id="etudiant" value="#{classeHasEtudiantController.selected.etudiant}" title="#{bundle.CreateClasseHasEtudiantTitle_etudiant}" required="true" requiredMessage="#{bundle.CreateClasseHasEtudiantRequiredMessage_etudiant}">
                    <f:selectItems value="#{etudiantController.itemsAvailableSelectOne}"/>
                </h:selectOneMenu>
                <h:outputLabel value="#{bundle.CreateClasseHasEtudiantLabel_classe}" for="classe" />
                <h:selectOneMenu id="classe" value="#{classeHasEtudiantController.selected.classe}" title="#{bundle.CreateClasseHasEtudiantTitle_classe}" required="true" requiredMessage="#{bundle.CreateClasseHasEtudiantRequiredMessage_classe}">
                    <f:selectItems value="#{classeController.itemsAvailableSelectOne}"/>
                </h:selectOneMenu>
            </h:panelGrid>
            <br />
            <h:commandLink action="#{classeHasEtudiantController.create}" value="#{bundle.CreateClasseHasEtudiantSaveLink}" />
            <br />
            <br />
            <h:commandLink action="#{classeHasEtudiantController.prepareList}" value="#{bundle.CreateClasseHasEtudiantShowAllLink}" immediate="true"/>
            <br />
            <br />
            <h:commandLink value="#{bundle.CreateClasseHasEtudiantIndexLink}" action="/index" immediate="true" />
        </h:form>
    </ui:define>

and this is my managedBean code :

    public String prepareCreate() {
    current = new ClasseHasEtudiant();
    current.setClasseHasEtudiantPK(new dossierEtudiants.entities.ClasseHasEtudiantPK());
    selectedItemIndex = -1;
    return "Create";
}

public String create() {
    try {
        getFacade().create(current);
        JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle1").getString("ClasseHasEtudiantCreated"));
        return prepareCreate();
    } catch (Exception e) {
        JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle1").getString("PersistenceErrorOccured"));
        return null;
    }
}

and finaly my log :

    Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`isetdb`.`classe_has_etudiant`, CONSTRAINT `classe_has_etudiant_ibfk_1` FOREIGN KEY (`Classe_id`) REFERENCES `classe` (`id`) ON DELETE CASCADE ON UPDATE CASCADE)
Error Code: 1452
Call: INSERT INTO classe_has_etudiant (Classe_id, Etudiant_id) VALUES (?, ?)
    bind => [2 parameters bound]
Query: InsertObjectQuery(entities.ClasseHasEtudiant[ classeHasEtudiantPK=entities.ClasseHasEtudiantPK[ classeid=0, etudiantid=0 ] ])
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:840)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:906)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:592)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:535)
    at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1702)
    at org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:253)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:207)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:193)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.insertObject(DatasourceCallQueryMechanism.java:342)
    at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:162)
    at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:177)
    at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.insertObjectForWrite(DatabaseQueryMechanism.java:472)
    at org.eclipse.persistence.queries.InsertObjectQuery.executeCommit(InsertObjectQuery.java:80)
    at org.eclipse.persistence.queries.InsertObjectQuery.executeCommitWithChangeSet(InsertObjectQuery.java:90)
    at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:287)
    at org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:58)
    at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:829)
    at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:728)
    at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:108)
    at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:85)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2863)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1501)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1483)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1443)
    at org.eclipse.persistence.internal.sessions.CommitManager.commitNewObjectsForClassWithChangeSet(CommitManager.java:224)
    at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:123)
    at org.eclipse.persistence.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:3784)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1407)
    at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:634)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1497)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.issueSQLbeforeCompletion(UnitOfWorkImpl.java:3135)
    at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.issueSQLbeforeCompletion(RepeatableWriteUnitOfWork.java:344)
    at org.eclipse.persistence.transaction.AbstractSynchronizationListener.beforeCompletion(AbstractSynchronizationListener.java:157)
    at org.eclipse.persistence.transaction.JTASynchronizationListener.beforeCompletion(JTASynchronizationListener.java:68)
    at com.sun.enterprise.transaction.JavaEETransactionImpl.commit(JavaEETransactionImpl.java:435)
    at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.commit(JavaEETransactionManagerSimplified.java:852)
    at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5114)
    at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4879)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2039)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1990)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
    at $Proxy302.create(Unknown Source)
    at sessionBeans.__EJB31_Generated__ClasseHasEtudiantFacade__Intf____Bean__.create(Unknown Source)
    at managedBeans.ClasseHasEtudiantController.create(ClasseHasEtudiantController.java:86)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
    at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:43)
    at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:56)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`isetdb`.`classe_has_etudiant`, CONSTRAINT `classe_has_etudiant_ibfk_1` FOREIGN KEY (`Classe_id`) REFERENCES `classe` (`id`) ON DELETE CASCADE ON UPDATE CASCADE)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
    at com.mysql.jdbc.Util.getInstance(Util.java:384)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1041)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2113)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2409)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2327)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2312)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:831)
    ... 87 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:13:55+00:00Added an answer on June 5, 2026 at 7:13 am

    Your database schema suggest that Classe_id is a foreign key.

    But while saving class you are assigning a new Primary key which basically sets classeid and etudiantid to zero, and while saving record there are no records with matching id.

    Current Implementation:

    current.setClasseHasEtudiantPK(new dossierEtudiants.entities.ClasseHasEtudiantPK());
    

    Instead you should set the id of Class and id of Student between which you are doing the mapping.

    Looking from the xhtml I think in your managed bean you would be having something like

    selected.classe which holds the selected class and selected.etudiant which holds the selected, so your code should look something like this:

    ClasseHasEtudiantPK classeHasEtudiantPK = new dossierEtudiants.entities.ClasseHasEtudiantPK(selected.classe.classeid, selected.etudiant.etudiantid);
    //Note depending upon your code the above two values selected.classe.classeid and selected.etudiant.etudinatid may change, so set according to your code.
    current.setClasseHasEtudiantPK(classeHasEtudiantPK);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am Using primefaces and Jsf with glassfish when i try to execute this
I'm using this jQuery snippet to create tooltips on some JSF primefaces elements in
I recently migrated my JSF app(using primefaces) from glassfish 3.1 to tomcat7 server. Previously
I'm using JSF 2.0 and it's new (actually old, but now incorporated in JSF)
My product is using JSF with Primefaces 2.2. What I need is to process
I am trying to learn JSF and was using JSF 2.0 along with PrimeFaces
I am doing a project where I am using JSF 2.0 & Primefaces UI
Simple question (using JSF 2.0 and primefaces 2.2.1): I need to create a button
I'm developing a web app using JSF 2.0 + PrimeFaces 2.2.1 Now I think
I am developing a Java web application using Hibernate and JSF/primefaces. am sometimes getting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.