Jpa - remove in M-M relationship

Hello,
I have these tables
USUARIO (1) - (M) USUARIO_SUBGRUPO (M) - SUBGRUPO
Entities:
Usuario.class
@OneToMany(cascade = CascadeType.ALL, mappedBy = "usuario")
private java.util.Collection <UsuarioSubgrupo> usuarioSubgrupoCollection;
UsuarioSubgrupo.class
@JoinColumn(name = "CD_USUAR", referencedColumnName = "CD_USUAR")
@ManyToOne
private Usuario usuario;
@JoinColumn(name = "CD_SUBGR", referencedColumnName = "CD_SUBGR")
@ManyToOne
private Subgrupo subgrupo;
Subgrupo
@OneToMany(cascade = CascadeType.ALL, mappedBy = "subgrupo")
private java.util.Collection <UsuarioSubgrupo> usuarioSubgrupoCollection;
I am trying to remove an User (Usuario) that has some datas in USUARIO_SUBGRUPO table like this:
em.getTransaction().begin();
// usuario is Managed
usuario = em.find(Usuario.class, id);
for (UsuarioSubgrupo us: usuario.getUsuarioSubgrupoCollection()) {
em.remove(em.merge(us));
us.setUsuario(null);
us.setSubgrupo(null);
usuario.setUsuarioSubgrupoCollection (null);
em.remove(em.merge(usuario));
em.getTransaction().commit();
And I am getting an error saying this cannot be done because Usuario has datas in UsuarioSubgrupo.
Could someone help me?
Thanks!

Hi,
I am sorry, the problem wasn't in the code but in database. I had some garbage in the USUARIO_SUBGRUPO table that make me get lost. Now it's working.
And about calling the merge, yes you're right, I saw that after send the post :)
Now my code is:
em.getTransaction().begin();
// usuario is Managed
usuario = em.find(Usuario.class, id);
usuario.getUsuarioSubgrupoCollection().
remove(usuario.getUsuarioSubgrupoCollection);
em.remove(usuario);
em.getTransaction().commit();
Thanks a lot.

Similar Messages

  • JPA: trouble removing a 1:M cascade ALL relationship from entity

    I have an entity A, with a OneToMany relationship to entity B, and cascade set to ALL.  Entity B has a ManyToOne relationship to A.  In my scenario I create a new instance of B to a detached instance of A, and I add it to the 1:M of A and set the M:1 on B.
    Then I'd like to merge the changes on A using EntityManager.merge(A).  However, before I do that I need to remove a different (old) instance of B from A, and then merge my changes so that my new instance of B is persisted.
    I've tried a couple different scenarios and get different results (none favorable):
    1.  First lookup the instance of B I want to remove via EntityManager.find(id), and then call EM.remove(B).  And then I call EM.merge(A) on the instance of A with my new B.  I get the following IllegalArgumentException during the merge:
    java.lang.IllegalArgumentException: Cannot fulfill merge operation: Relationship >>outputElementInstances<< of the target entity {com.sap.eventus.wire.entity.EvtWireInstance(id=85e83543-45d1-49cd-bb90-8688699ca0d4)} has been modified
    The relationship it's talking about is actually a different (but related) one that was affected when the old instance of B was removed.  It seems reasonable that JPA has determined that my instance of A with the new B is no longer in sync with the database and is complaining that a relationship has been changed.
    Any ways around that?
    2. I also tried simply removing B from A's 1:M, and setting B's M:1 to null, and then merging in hopes that would trigger a delete on the old B.  However the old B is not removed.
    I was expecting this to trigger a delete, however, I realize that there are other relationships from B to other objects (such as a 1:M cascade ALL) that I did not remove which I suspect might cause JPA to not delete the old B.  Is this true?
    3. And finally I tried 1 & 2 together, first calling EM.remove(old B), and then removing the old B from A and then merging, which yields the following IllegalStateException:
    java.lang.IllegalStateException: Relationship >>wireInstance<< of entity {com.sap.eventus.wire.entity.EvtElementInstance(id=08ca6253-1385-45dd-9173-978ee298b55f)} contains the new entity {com.sap.eventus.wire.entity.EvtWireInstance(id=c9fbd4e7-5575-4cc9-9b7d-2a8549c43574)}
    Which is another different (but related) relationship off of object B.
    Basically, after all this, my question is: what is the correct way to remove a 1:M relationship and add a new one?  Simple enough, however I do not want to remove the old 1:M, re-query to get the new updated parent object and then add the new 1:M, as it's a fairly involved in creating and adding the new 1:M and it must be done BEFORE removing the old 1:M.
    Thanks!

    Hi Derek,
    I understand your task as follows:
    You are having three entities A, B_old and B_new. Within one transaction you want to do the following:
    - remove B_old from the database
    - remove B_old from the 1:n relationship A.bs
    - persist the B_new
    - add B_new to the 1:n relationship A.bs
    - set the n:1 relationship B_new.a to refer to A
    well, I suggest that you do this without a merge:
    - em.remove(B_old)  // you have to do this explicitly as JPA 1 does not have automatic orphan removal
    - A.bs.remove(B_old)
    - em.persist(B_new) // also, you have to make sure that the entities related to B_new are managed upon commit
    - A.bs.add(B_new)
    - B_new.a = A
    I hope this works.
    Regarding your observations:
    1. The error message is not self-explaining. We have got to improve it ;-).
    2. You have to remove the B_old explicitly as JPA 1 does not have automatic orphan removal. 
    3. This message should be self-explaining. Maybe there is one of the relationships EvtOutputElementInstance.wireInstance or EvtInputElementInstance.wireInstance still referring B_new. You'll surely find out.
    Regards,
    Adrian

  • Recursive Parent Child relationship in JPA

    @Entity
    @Table(name = "OBJECTCATEGORY")
    public class ObjectCategory implements Serializable {
         @Id
         private String categoryId;
         private String categoryName;
         private String description;
         private static final long serialVersionUID = 1L;
         @ManyToMany(fetch = FetchType.EAGER)
         @JoinTable(name = "MAP_CATEGORY", joinColumns = @JoinColumn(name = "CATEGORYID"), inverseJoinColumns = @JoinColumn(name = "OBJECTID"))
         private List<MapC> mapList = new ArrayList<MapC>();
    // Recursion
         @OneToMany(fetch = FetchType.LAZY, mappedBy = "fqQuesCatagory")
         List<ObjectCategory > categoryList = new ArrayList<ObjectCategory>();
         @ManyToOne
         @JoinColumn(name = "PARENTCATEGORY")
         private ObjectCategory fqQuesCatagory
    // Recursion
         public FqQuesCatagory() {
              super();
         public String getCategoryname() {
              return this.categoryname;
         public void setCategoryname(String categoryname) {
              this.categoryname = categoryname;
         public String getDescription() {
              return this.description;
         public void setDescription(String description) {
              this.description = description;
         public List<MapC> getMapList() {
              return faqList;
         public void setFaqList(List<MapC> faqList) {
              this.mapList = mapList ;
         public String getCategoryid() {
              return categoryId;
         public void setCategoryid(String categoryid) {
              this.categoryid = categoryId;
         public List<ObjectCategory> getFqCategoryList() {
              return categoryList;
         public void setFqCategoryList(List<ObjectCategory> categoryList) {
              this.categoryList = categoryList;
         public ObjectCategory getFqQuesCatagory() {
              return fqQuesCatagory;
         public void setFqQuesCatagory(ObjectCategory fqQuesCatagory) {
              this.fqQuesCatagory = fqQuesCatagory;
    Doesn't SAP JPA support recursive parent-child relationship (highlighted by "// Recursion"). The same model works in TopLink perfectly.

    Sorry for the delayed update..
    I see an issue in the WSNavigator. I have a method in my EJB exposed as a web service. This method has a single argument, which is a serializable class containing a few string variables and the above-mentioned Entity with suitable getters and setters for all the class variables.
    When I try to select this operation under the WSDL in the Webservice Navigator, I get a stack overflow error. I think it is because WD4J run-time is not able to build the nested tree. Not sure though...I've attached the stack trace below:
    Cannot send an HTTP error response [500 "Application error occurred during the request procession." (details: java.lang.StackOverflowError
    at java.lang.String.lastIndexOf(String.java:1496)
    at java.lang.String.lastIndexOf(String.java:1458)
    at com.sap.dictionary.runtime.StringUtil.getPackageName(StringUtil.java:143)
    at com.sap.dictionary.runtime.DdBroker.getDataType(DdBroker.java:179)
    at com.sap.tc.webdynpro.progmodel.context.DictionaryHandler._getScalarType(DictionaryHandler.java:447)
    at com.sap.tc.webdynpro.progmodel.context.DictionaryHandler.getDataType(DictionaryHandler.java:159)
    at com.sap.tc.webdynpro.progmodel.context.DataAttributeInfo.init(DataAttributeInfo.java:447)
    at com.sap.tc.webdynpro.progmodel.context.NodeInfo.addAttribute(NodeInfo.java:746)
    at com.sap.tc.webdynpro.progmodel.context.NodeInfo.addAttribute(NodeInfo.java:759)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder.createParameterNodeInfo(DWSContextBuilder.java:984)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder.access$400(DWSContextBuilder.java:88)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.buildContextForComplexType(DWSContextBuilder.java:1591)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.buildContextForTypeObject(DWSContextBuilder.java:1574)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createElementObject(DWSContextBuilder.java:1763)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createFieldObject(DWSContextBuilder.java:1681)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.intWithStructureFields(DWSContextBuilder.java:1671)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createComplexTypeObject(DWSContextBuilder.java:1660)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.buildContextForComplexType(DWSContextBuilder.java:1615)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.buildContextForTypeObject(DWSContextBuilder.java:1574)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createElementObject(DWSContextBuilder.java:1763)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createFieldObject(DWSContextBuilder.java:1681)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.intWithStructureFields(DWSContextBuilder.java:1671)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createComplexTypeObject(DWSContextBuilder.java:1660)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.buildContextForComplexType(DWSContextBuilder.java:1615)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.buildContextForTypeObject(DWSContextBuilder.java:1574)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createElementObject(DWSContextBuilder.java:1763)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createFieldObject(DWSContextBuilder.java:1681)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.intWithStructureFields(DWSContextBuilder.java:1671)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createComplexTypeObject(DWSContextBuilder.java:1660)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.buildContextForComplexType(DWSContextBuilder.java:1615)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.buildContextForTypeObject(DWSContextBuilder.java:1574)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createElementObject(DWSContextBuilder.java:1763)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createFieldObject(DWSContextBuilder.java:1681)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.intWithStructureFields(DWSContextBuilder.java:1671)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createComplexTypeObject(DWSContextBuilder.java:1660)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.buildContextForComplexType(DWSContextBuilder.java:1615)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.buildContextForTypeObject(DWSContextBuilder.java:1574)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createElementObject(DWSContextBuilder.java:1763)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createFieldObject(DWSContextBuilder.java:1681)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.intWithStructureFields(DWSContextBuilder.java:1671)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createComplexTypeObject(DWSContextBuilder.java:1660)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.buildContextForComplexType(DWSContextBuilder.java:1615)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.buildContextForTypeObject(DWSContextBuilder.java:1574)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createElementObject(DWSContextBuilder.java:1763)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createFieldObject(DWSContextBuilder.java:1681)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.intWithStructureFields(DWSContextBuilder.java:1671)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createComplexTypeObject(DWSContextBuilder.java:1660)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.buildContextForComplexType(DWSContextBuilder.java:1615)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.buildContextForTypeObject(DWSContextBuilder.java:1574)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createElementObject(DWSContextBuilder.java:1763)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createFieldObject(DWSContextBuilder.java:1681)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.intWithStructureFields(DWSContextBuilder.java:1671)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createComplexTypeObject(DWSContextBuilder.java:1660)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.buildContextForComplexType(DWSContextBuilder.java:1615)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.buildContextForTypeObject(DWSContextBuilder.java:1574)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createElementObject(DWSContextBuilder.java:1763)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.createFieldObject(DWSContextBuilder.java:1681)
    at com.sap.esi.esp.wsnavigator.helper.DWSContextBuilder$DInputParams.intWithStructureFields(DWSContextBuilder.java:1671)
    Any thoughts on this will be highly appreciated.
    BR.

  • Looped relationships in template of custom class

    a while  back i
    submitted a question regarding custom form design and many to one relationships. The answer provided there got me onto the right path, and I was able to implement those forms and they successfully create items in the database and work as expected.
    Now I've run into a different issue when using these forms to create templates. The template that is created includes a looped relationship between the child and the parent. here is an example of the template created: 
    <Templates>
    <ObjectTemplate ID="Template.fec63f0df22440b1a420724c9ae400ec" TypeID="MaintenanceSchedules!System.WorkItem.MaintenanceScheduleProjection.FormProjection">
    <Property Path="$Context/Property[Type='CustomSystem_WorkItem_Library!System.WorkItem']/Title$">Parent Schedule</Property>
    <Object Path="$Context/Path[Relationship='MaintenanceSchedules!ContainsMaintenanceAction' TypeConstraint='MaintenanceSchedules!System.WorkItem.MaintenanceAction.Schedule']$">
    <Property Path="$Context/Property[Type='CustomSystem_WorkItem_Library!System.WorkItem']/Title$">Child Action</Property>
    <Object Path="$Context/Path[Relationship='MaintenanceSchedules!ContainsMaintenanceAction' SeedRole='Target' TypeConstraint='MaintenanceSchedules!System.WorkItem.MaintenanceSchedule']$">
    <Property Path="$Context/Property[Type='CustomSystem_WorkItem_Library!System.WorkItem']/Title$">Parent Schedule</Property>
    </Object>
    </Object>
    </ObjectTemplate>
    </Templates>
    I'll direct your attention to the relationship marked with SeedRole='Target'; it is a duplicate. When applying this template, the relationship from parent to child is created, and then the child's projection attempts to create the same relationship from
    child to parent, and obviously fails, throwing an exception. this doesn't seem to happen with other similar relationships like System.WorkItemContainsActivity that is used in Service Request templates, and removing this relationship from the Management Pack
    XML allows the template to work as expected. 
    My question is why this extra looped relationship is being inserted in the template, when it is apparently not being inserted into the database? Am I missing a step to clean up the projection for submission as a template? should i be calling something during
    the form's OnPreviewSubmit() method when IsFormInTemplateMode is true?
    My first through was to remove the SeedRole='Target' relationship from the child projection, but that seems to break the projection mergers in the form code from the last question, and the out-of-the-box service request form projections do have these relationships. 
    For Reference, here are the projections used to populate the forms: 
    <TypeProjections>
    <TypeProjection ID="System.WorkItem.MaintenanceScheduleProjection.FormProjection" Accessibility="Public" Type="System.WorkItem.MaintenanceSchedule">
    <Component Path="$Target/Path[Relationship='ContainsMaintenanceAction']$" Alias="Action" />
    <Component Path="$Target/Path[Relationship='MaintainsConfigItem']$" Alias="MaintainsConfigItem" />
    <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemAssignedToUser']$" Alias="AssignedTo" />
    <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemCreatedByUser']$" Alias="CreatedBy" />
    <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemRelatesToConfigItem']$" Alias="RelatedConfigItems" />
    <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemAboutConfigItem']$" Alias="AboutConfigItem" />
    <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemRelatesToWorkItem']$" Alias="RelatedWorkItems">
    <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemAssignedToUser']$" Alias="RelatedWorkItemAssignedTo" />
    </Component>
    <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemRelatesToWorkItem' SeedRole='Target']$" Alias="RelatedWorkItemSource">
    <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemAssignedToUser']$" Alias="RelatedWorkItemAssignedTo" />
    </Component>
    <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemHasFileAttachment']$" Alias="FileAttachments">
    <Component Path="$Target/Path[Relationship='SupportingItem!System.FileAttachmentAddedByUser']$" Alias="FileAttachmentAddedBy" />
    </Component>
    <Component Path="$Target/Path[Relationship='CoreKnowledge!System.EntityLinksToKnowledgeDocument']$" Alias="RelatedKnowledgeArticles" />
    </TypeProjection>
    <!-- SNIP: removed unrelated projections --->
    <TypeProjection ID="System.WorkItem.MaintenanceAction.Schedule.FormProjection" Accessibility="Public" Type="System.WorkItem.MaintenanceAction.Schedule">
    <Component Path="$Target/Path[Relationship='ContainsMaintenanceAction' SeedRole='Target']$" Alias="Schedule" />
    <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemAssignedToUser']$" Alias="AssignedTo" />
    <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemCreatedByUser']$" Alias="CreatedBy" />
    <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemRelatesToConfigItem']$" Alias="RelatedConfigItems" />
    <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemAboutConfigItem']$" Alias="AboutConfigItem" />
    <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemRelatesToWorkItem']$" Alias="RelatedWorkItems">
    <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemAssignedToUser']$" Alias="RelatedWorkItemAssignedTo" />
    </Component>
    <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemRelatesToWorkItem' SeedRole='Target']$" Alias="RelatedWorkItemSource">
    <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemAssignedToUser']$" Alias="RelatedWorkItemAssignedTo" />
    </Component>
    <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemHasFileAttachment']$" Alias="FileAttachments">
    <Component Path="$Target/Path[Relationship='SupportingItem!System.FileAttachmentAddedByUser']$" Alias="FileAttachmentAddedBy" />
    </Component>
    <Component Path="$Target/Path[Relationship='CoreKnowledge!System.EntityLinksToKnowledgeDocument']$" Alias="RelatedKnowledgeArticles" />
    </TypeProjection>
    </TypeProjections>

    Ya, i really don't. C# and WPF are strange and mysterious worlds to which I have a vague map, largely marked "here be dragons". 
    I'm a Core Infrastructure consultant and process engineer in my real time job. I scoped this maintenance process as a 4 week development gig, because I expected to be able to create a couple of authoring tool classes, 3-4 finite state workflows, one
    custom control for the many-to-one relationship and call it done. You can probably guess how well that went. 
    This was my first foray into the console SDK, but I do a lot of workflow and process automation is power shell, so i'm familiar enough with the back-end data structures and presentation methods to make informed guesses about how the functions SHOULD work,
    but, again, you can probably guess how well that went this time. 
    Thanks again for the assistance. I'm going to go pick up a copy of the .Net reflector if i keep doing this. almost everything I want to do is something that MS has already done at least once in the console somewhere, and the documentation that Microsoft
    provides is.... thin; Google has three references to the IsFormInTemplateMode() function, and two of them are you and I. 

  • Contact Person Relationship to SP.

    Hi Experts,
    I am faced up with a situation; where if am removing a Contact Person relationship for a Sold to Party; the relationship to the another contact person gets deleted. Possible reason could be both the contact person are identical.
    Now, how can i identify whether both the Cont. Person are identical or not; even though GUID for both is different. Is there any field value that makes them identical.

    Hi,
    I have gone through your query. The question here is bit misleading. You have mentioned that when you delete the contact person relationship of a Sold to party, relationship to another contact person is deleted. No two contact persons can be identical in the system. Whenever you create a new BP in the CRM system, every one are unique in its own way with a New GUID and New BP number assigned to them.
    Even though they can remain as duplicate, but 2 contact persons cannot be identical which will lead to a scenario like you have mentioned here. In my opinion this cannot occur. If you elaborate further i can help you out.
    I hope this helps.
    Regards,
    Venkat

  • JPA Object-Relational Mapping: how to deal with self-related mapping?

    ignore the post.
    sorry for my stupidity
    ==
    Hello,
    Suppose I have a class nemed Group, which can have sub-groups. It is defined like:
    @Entity
    Class Group{
    private int id;
    private String name;
    private Group parent; //M-1 mapping
    The problem is Group is mapped to itself:
    child group -- parent group
    M : 1
    How JPA supports that kind of relationship? Can I put both
    @Many-to-One and @One-to-Many over parent field like:
    @Many-to-One
    @One-to-Many
    private Group parent;
    Thanks a lot!
    Message was edited by:
    javasprinter

    One possibility could be the following - (included annotation mappings):
    @Entity
    Class Group{
    private int id; // probably should change to Integer to account for null data
    private String name;
    @ManyToOne
    @JoinColumn(name = "PARENT_GROUP_FK")
    private Group parent; //M-1 mapping
    @OneToMany
    @JoinTable ( name = "SUB_GROUPS",
    joinColumns = { @JoinColumn(name = "PARENT_GROUP_ID")},
    inverseJoinColumns = {@JoinColumn(name = "CHILD_GROUP_ID")}
    private List subGroups;
    Tables -
    Group - columns - id, name, parent_group_fk
    Sub_groups - columns - parent_group_id, child_group_id
    The above maps a unidirectional relationship from parent group to child groups, but that really isn't a big deal because you can always get the parent from the parent group id.
    I'm sure this isn't the best way, but it worked for me. HTH.

  • Error relationship one to many

    I'm having a problem using JPA (toplink) / Jaybird with a relationship for many:
    Call the methods:
    EmpresaFacadeRemote empresa = (EmpresaFacadeRemote) ic.lookup("br.teste.app.beans.EmpresaFacadeRemote");
    empresa.createEmpresa(jtfRasaoSocial.getText(), jtfNomeFantasia.getText(), jtfCpfCnpj.getText(), jtfRgInscEstadual.getText());
    empresa.addMeioContato(meiosContatoList);package br.teste.app.beans;
    <strong>Session Beans:</strong>
    import br.teste.app.entidades.MeioContato;
    import br.teste.app.entidades.Pessoa;
    import java.util.List;
    import javax.ejb.Stateful;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    import javax.persistence.PersistenceContextType;
    * @author kurumin
    @Stateful
    public class EmpresaFacade implements EmpresaFacadeRemote {
        @PersistenceContext(type=PersistenceContextType.TRANSACTION)
        private EntityManager em;
        public Pessoa createEmpresa(String rasaoSocial, String nomeFantasia, String cnpj, String inscricaiEstadual) {
            this.empresa = new Pessoa(rasaoSocial, nomeFantasia, cnpj, inscricaiEstadual,"EM",'J');
            em.persist(empresa);
            return empresa;
        public Pessoa createEmpresa(Pessoa empresa, List&lt;MeioContato&gt; meiosContatoList) {
            this.empresa = empresa;
            empresa.setMeioContatoCollection(meiosContatoList);
            em.persist(empresa);
            return empresa;
        public void addMeioContato(List&lt;MeioContato&gt; meiosContatoList) {
            this.empresa.setMeioContatoCollection(meiosContatoList);
            em.merge(empresa);
        private Pessoa empresa;
    <strong>Entity Beans</strong>
    package br.teste.app.entidades;
    import java.io.Serializable;
    import java.util.Collection;
    import java.util.Date;
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.NamedQueries;
    import javax.persistence.NamedQuery;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
    * @author kurumin
    @Entity
    @Table(name = "PESSOA")
    @NamedQueries({@NamedQuery(name = "Pessoa.findByCodigo", query = "SELECT p FROM Pessoa p WHERE p.codigo = :codigo")})
    public class Pessoa implements Serializable {
        private static final long serialVersionUID = 1L;
        @Id
        @Column(name = "CODIGO", nullable = false)
        private Integer codigo;
        @Column(name = "NOME", nullable = false)
        private String nome;
        @Column(name = "APELIDO")
        private String apelido;
        @Column(name = "CPF_CNPJ", nullable = false)
        private String cpfCnpj;
        @Column(name = "RG_INSCRICAO")
        private String rgInscricao;
        @Column(name = "ORGAO_EXPEDIDOR")
        private String orgaoExpedidor;
        @Column(name = "UF")
        private String uf;
        @Column(name = "FOTO_LOGOMARCA")
        private String fotoLogomarca;
        @Column(name = "TIPO", nullable = false)
        private String tipo;
        @Column(name = "TIPO_PESSOA", nullable = false)
        private char tipoPessoa;
        @Column(name = "DATA_CADASTRO")
        @Temporal(TemporalType.DATE)
        private Date dataCadastro;
        @Column(name = "OBSERVACAO")
        private String observacao;
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "pessoaCodg")
        private Collection&lt;MeioContato&gt; meioContatoCollection;
        public Pessoa() {
        public Pessoa(String nome, String apelido, String cpfCnpj, String rgInscricao,
                     String orgaoExpedidor, String uf, String tipo, char tipoPessoa) {
            this.nome = nome;
            this.apelido = apelido;
            this.cpfCnpj = cpfCnpj;
            this.rgInscricao = rgInscricao;
            this.orgaoExpedidor = orgaoExpedidor;
            this.uf = uf;
            this.tipo = tipo;
            this.tipoPessoa = tipoPessoa;      
        public Pessoa(String nome, String apelido, String cpfCnpj, String rgInscricao,
                                                      String tipo, char tipoPessoa) {
            this.nome = nome;
            this.apelido = apelido;
            this.cpfCnpj = cpfCnpj;
            this.rgInscricao = rgInscricao;
            this.tipo = tipo;
            this.tipoPessoa = tipoPessoa;
        public Integer getCodigo() {
            return codigo;
        public void setCodigo(Integer codigo) {
            this.codigo = codigo;
        public String getNome() {
            return nome;
        public void setNome(String nome) {
            this.nome = nome;
        public String getApelido() {
            return apelido;
        public void setApelido(String apelido) {
            this.apelido = apelido;
        public String getCpfCnpj() {
            return cpfCnpj;
        public void setCpfCnpj(String cpfCnpj) {
            this.cpfCnpj = cpfCnpj;
        public String getRgInscricao() {
            return rgInscricao;
        public void setRgInscricao(String rgInscricao) {
            this.rgInscricao = rgInscricao;
        public String getOrgaoExpedidor() {
            return orgaoExpedidor;
        public void setOrgaoExpedidor(String orgaoExpedidor) {
            this.orgaoExpedidor = orgaoExpedidor;
        public String getUf() {
            return uf;
        public void setUf(String uf) {
            this.uf = uf;
        public String getFotoLogomarca() {
            return fotoLogomarca;
        public void setFotoLogomarca(String fotoLogomarca) {
            this.fotoLogomarca = fotoLogomarca;
        public String getTipo() {
            return tipo;
        public void setTipo(String tipo) {
            this.tipo = tipo;
        public char getTipoPessoa() {
            return tipoPessoa;
        public void setTipoPessoa(char tipoPessoa) {
            this.tipoPessoa = tipoPessoa;
        public Date getDataCadastro() {
            return dataCadastro;
        public void setDataCadastro(Date dataCadastro) {
            this.dataCadastro = dataCadastro;
        public String getObservacao() {
            return observacao;
        public void setObservacao(String observacao) {
            this.observacao = observacao;
        public Collection&lt;MeioContato&gt; getMeioContatoCollection() {
            return meioContatoCollection;
        public void setMeioContatoCollection(Collection&lt;MeioContato&gt; meioContatoCollection) {
            this.meioContatoCollection = meioContatoCollection;
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (codigo != null ? codigo.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 Pessoa)) {
                return false;
            Pessoa other = (Pessoa) object;
            if ((this.codigo == null && other.codigo != null) || (this.codigo != null && !this.codigo.equals(other.codigo))) {
                return false;
            return true;
        @Override
        public String toString() {
            return "br.teste.app.entidades.Pessoa[codigo=" + codigo + "]";
    package br.teste.app.entidades;
    import java.io.Serializable;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.NamedQueries;
    import javax.persistence.NamedQuery;
    import javax.persistence.Table;
    * @author kurumin
    @Entity
    @Table(name = "MEIO_CONTATO")
    @NamedQueries({@NamedQuery(name = "MeioContato.findByMeioContato", query = "SELECT m FROM MeioContato m WHERE m.meioContato = :meioContato")})
    public class MeioContato implements Serializable {
        private static final long serialVersionUID = 1L;
        @Column(name = "MEIO_CONTATO", nullable = false)
        private String meioContato;
        @Column(name = "TIPO", nullable = false)
        private String tipo;
        @Column(name = "RESPONSAVEL")
        private String responsavel;
        @Id
        @Column(name = "DESCRICAO", nullable = false)
        private String descricao;
        @Column(name = "SETOR")
        private String setor;
        @JoinColumn(name = "PESSOA_CODG", referencedColumnName = "CODIGO")
        @ManyToOne
        private Pessoa pessoaCodg;
        public MeioContato() {
        public MeioContato(String tipo, String meioContato, String setor, String resposavel, String descricao) {
            this.descricao = descricao;
            this.meioContato = meioContato;
            this.tipo = tipo;
            this.responsavel = resposavel;
            this.setor = setor;
        public String getMeioContato() {
            return meioContato;
        public void setMeioContato(String meioContato) {
            this.meioContato = meioContato;
        public String getTipo() {
            return tipo;
        public void setTipo(String tipo) {
            this.tipo = tipo;
        public String getResponsavel() {
            return responsavel;
        public void setResponsavel(String responsavel) {
            this.responsavel = responsavel;
        public String getDescricao() {
            return descricao;
        public void setDescricao(String descricao) {
            this.descricao = descricao;
        public String getSetor() {
            return setor;
        public void setSetor(String setor) {
            this.setor = setor;
        public Pessoa getPessoaCodg() {
            return pessoaCodg;
        public void setPessoaCodg(Pessoa pessoaCodg) {
            this.pessoaCodg = pessoaCodg;
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (descricao != null ? descricao.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 MeioContato)) {
                return false;
            MeioContato other = (MeioContato) object;
            if ((this.descricao == null && other.descricao != null) || (this.descricao != null && !this.descricao.equals(other.descricao))) {
                return false;
            return true;
        @Override
        public String toString() {
            return "br.teste.app.entidades.MeioContato[descricao=" + descricao + "]";
    <font color="#ff0000">Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544665. violation of PRIMARY or UNIQUE KEY constraint "UNQ_PESSOA_CPF" on table "PESSOA"
    Error Code: 335544665
    Call: INSERT INTO PESSOA (CODIGO, UF, FOTO_LOGOMARCA, APELIDO, TIPO, RG_INSCRICAO, TIPO_PESSOA, NOME, DATA_CADASTRO, ORGAO_EXPEDIDOR, OBSERVACAO, CPF_CNPJ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
            bind =&gt; [null, null, null, kjkjk, EM, jkjljlj, J, julkjlkjl, null, null, null, jkjkj222]</font>
    Another way to call the methods:
            EmpresaFacadeRemote empresa = (EmpresaFacadeRemote) ic.lookup("br.teste.app.beans.EmpresaFacadeRemote");
            private Pessoa entidadePessoa = new Pessoa(jtfRasaoSocial.getText(), jtfNomeFantasia.getText(),  jtfCpfCnpj.getText(), jtfRgInscEstadual.getText(),"EM",'J');
            empresa.createEmpresa(entidadePessoa,meiosContatoList);
    package br.teste.app.beans;<br />
    <br />
    <strong>Session Beans:</strong><br />
    <br />
    import br.teste.app.entidades.MeioContato;<br />
    import br.teste.app.entidades.Pessoa;<br />
    import java.util.List;<br />
    import javax.ejb.Stateful;<br />
    import javax.persistence.EntityManager;<br />
    import javax.persistence.PersistenceContext;<br />
    import javax.persistence.PersistenceContextType;<br />
    <br />
    /**<br />
    *<br />
    * @author kurumin<br />
    */<br />
    @Stateful<br />
    public class EmpresaFacade implements EmpresaFacadeRemote {<br />
        @PersistenceContext(type=PersistenceContextType.TRANSACTION)<br />
        private EntityManager em;<br />
       <br />
        public Pessoa createEmpresa(String rasaoSocial, String nomeFantasia, String cnpj, String inscricaiEstadual) {<br />
            this.empresa = new Pessoa(rasaoSocial, nomeFantasia, cnpj, inscricaiEstadual,"EM",'J');<br />
            em.persist(empresa);<br />
            return empresa;<br />
        }<br />
    <br />
        public Pessoa createEmpresa(Pessoa empresa, List&lt;MeioContato&gt; meiosContatoList) {<br />
            this.empresa = empresa;<br />
            empresa.setMeioContatoCollection(meiosContatoList);<br />
            em.persist(empresa);<br />
            return empresa;<br />
        }<br />
       <br />
        public void addMeioContato(List&lt;MeioContato&gt; meiosContatoList) {<br />
            this.empresa.setMeioContatoCollection(meiosContatoList);<br />
            em.merge(empresa);<br />
        }<br />
       <br />
        private Pessoa empresa;<br />
    <br />
    }<br />
    <br />
    <strong>Entity Beans</strong><br />
    <br />
    <br />
    package br.teste.app.entidades;<br />
    <br />
    import java.io.Serializable;<br />
    import java.util.Collection;<br />
    import java.util.Date;<br />
    import javax.persistence.CascadeType;<br />
    import javax.persistence.Column;<br />
    import javax.persistence.Entity;<br />
    import javax.persistence.Id;<br />
    import javax.persistence.NamedQueries;<br />
    import javax.persistence.NamedQuery;<br />
    import javax.persistence.OneToMany;<br />
    import javax.persistence.Table;<br />
    import javax.persistence.Temporal;<br />
    import javax.persistence.TemporalType;<br />
    <br />
    /**<br />
    *<br />
    * @author kurumin<br />
    */<br />
    @Entity<br />
    @Table(name = "PESSOA")<br />
    @NamedQueries({@NamedQuery(name = "Pessoa.findByCodigo", query = "SELECT p FROM Pessoa p WHERE p.codigo = :codigo"), @NamedQuery(name = "Pessoa.findByNome", query = "SELECT p FROM Pessoa p WHERE p.nome = :nome"), @NamedQuery(name = "Pessoa.findByApelido", query = "SELECT p FROM Pessoa p WHERE p.apelido = :apelido"), @NamedQuery(name = "Pessoa.findByCpfCnpj", query = "SELECT p FROM Pessoa p WHERE p.cpfCnpj = :cpfCnpj"), @NamedQuery(name = "Pessoa.findByRgInscricao", query = "SELECT p FROM Pessoa p WHERE p.rgInscricao = :rgInscricao"), @NamedQuery(name = "Pessoa.findByOrgaoExpedidor", query = "SELECT p FROM Pessoa p WHERE p.orgaoExpedidor = :orgaoExpedidor"), @NamedQuery(name = "Pessoa.findByUf", query = "SELECT p FROM Pessoa p WHERE p.uf = :uf"), @NamedQuery(name = "Pessoa.findByFotoLogomarca", query = "SELECT p FROM Pessoa p WHERE p.fotoLogomarca = :fotoLogomarca"), @NamedQuery(name = "Pessoa.findByTipo", query = "SELECT p FROM Pessoa p WHERE p.tipo = :tipo"), @NamedQuery(name = "Pessoa.findByTipoPessoa", query = "SELECT p FROM Pessoa p WHERE p.tipoPessoa = :tipoPessoa"), @NamedQuery(name = "Pessoa.findByDataCadastro", query = "SELECT p FROM Pessoa p WHERE p.dataCadastro = :dataCadastro"), @NamedQuery(name = "Pessoa.findByObservacao", query = "SELECT p FROM Pessoa p WHERE p.observacao = :observacao")})<br />
    public class Pessoa implements Serializable {<br />
        private static final long serialVersionUID = 1L;<br />
        @Id<br />
        @Column(name = "CODIGO", nullable = false)<br />
        private Integer codigo;<br />
        @Column(name = "NOME", nullable = false)<br />
        private String nome;<br />
        @Column(name = "APELIDO")<br />
        private String apelido;<br />
        @Column(name = "CPF_CNPJ", nullable = false)<br />
        private String cpfCnpj;<br />
        @Column(name = "RG_INSCRICAO")<br />
        private String rgInscricao;<br />
        @Column(name = "ORGAO_EXPEDIDOR")<br />
        private String orgaoExpedidor;<br />
        @Column(name = "UF")<br />
        private String uf;<br />
        @Column(name = "FOTO_LOGOMARCA")<br />
        private String fotoLogomarca;<br />
        @Column(name = "TIPO", nullable = false)<br />
        private String tipo;<br />
        @Column(name = "TIPO_PESSOA", nullable = false)<br />
        private char tipoPessoa;<br />
        @Column(name = "DATA_CADASTRO")<br />
        @Temporal(TemporalType.DATE)<br />
        private Date dataCadastro;<br />
        @Column(name = "OBSERVACAO")<br />
        private String observacao;<br />
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "pessoaCodg")<br />
        private Collection&lt;MeioContato&gt; meioContatoCollection;<br />
    <br />
        public Pessoa() {<br />
        }<br />
    <br />
        public Pessoa(String nome, String apelido, String cpfCnpj, String rgInscricao,<br />
                     String orgaoExpedidor, String uf, String tipo, char tipoPessoa) {<br />
            this.nome = nome;<br />
            this.apelido = apelido;<br />
            this.cpfCnpj = cpfCnpj;<br />
            this.rgInscricao = rgInscricao;<br />
            this.orgaoExpedidor = orgaoExpedidor;<br />
            this.uf = uf;<br />
            this.tipo = tipo;<br />
            this.tipoPessoa = tipoPessoa;       <br />
        }<br />
    <br />
        public Pessoa(String nome, String apelido, String cpfCnpj, String rgInscricao,<br />
                                                      String tipo, char tipoPessoa) {<br />
            this.nome = nome;<br />
            this.apelido = apelido;<br />
            this.cpfCnpj = cpfCnpj;<br />
            this.rgInscricao = rgInscricao;<br />
            this.tipo = tipo;<br />
            this.tipoPessoa = tipoPessoa;<br />
        }<br />
    <br />
        public Integer getCodigo() {<br />
            return codigo;<br />
        }<br />
    <br />
        public void setCodigo(Integer codigo) {<br />
            this.codigo = codigo;<br />
        }<br />
    <br />
        public String getNome() {<br />
            return nome;<br />
        }<br />
    <br />
        public void setNome(String nome) {<br />
            this.nome = nome;<br />
        }<br />
    <br />
        public String getApelido() {<br />
            return apelido;<br />
        }<br />
    <br />
        public void setApelido(String apelido) {<br />
            this.apelido = apelido;<br />
        }<br />
    <br />
        public String getCpfCnpj() {<br />
            return cpfCnpj;<br />
        }<br />
    <br />
        public void setCpfCnpj(String cpfCnpj) {<br />
            this.cpfCnpj = cpfCnpj;<br />
        }<br />
    <br />
        public String getRgInscricao() {<br />
            return rgInscricao;<br />
        }<br />
    <br />
        public void setRgInscricao(String rgInscricao) {<br />
            this.rgInscricao = rgInscricao;<br />
        }<br />
    <br />
        public String getOrgaoExpedidor() {<br />
            return orgaoExpedidor;<br />
        }<br />
    <br />
        public void setOrgaoExpedidor(String orgaoExpedidor) {<br />
            this.orgaoExpedidor = orgaoExpedidor;<br />
        }<br />
    <br />
        public String getUf() {<br />
            return uf;<br />
        }<br />
    <br />
        public void setUf(String uf) {<br />
            this.uf = uf;<br />
        }<br />
    <br />
        public String getFotoLogomarca() {<br />
            return fotoLogomarca;<br />
        }<br />
    <br />
        public void setFotoLogomarca(String fotoLogomarca) {<br />
            this.fotoLogomarca = fotoLogomarca;<br />
        }<br />
    <br />
        public String getTipo() {<br />
            return tipo;<br />
        }<br />
    <br />
        public void setTipo(String tipo) {<br />
            this.tipo = tipo;<br />
        }<br />
    <br />
        public char getTipoPessoa() {<br />
            return tipoPessoa;<br />
        }<br />
    <br />
        public void setTipoPessoa(char tipoPessoa) {<br />
            this.tipoPessoa = tipoPessoa;<br />
        }<br />
    <br />
        public Date getDataCadastro() {<br />
            return dataCadastro;<br />
        }<br />
    <br />
        public void setDataCadastro(Date dataCadastro) {<br />
            this.dataCadastro = dataCadastro;<br />
        }<br />
    <br />
        public String getObservacao() {<br />
            return observacao;<br />
        }<br />
    <br />
        public void setObservacao(String observacao) {<br />
            this.observacao = observacao;<br />
        }<br />
    <br />
        public Collection&lt;MeioContato&gt; getMeioContatoCollection() {<br />
            return meioContatoCollection;<br />
        }<br />
    <br />
        public void setMeioContatoCollection(Collection&lt;MeioContato&gt; meioContatoCollection) {<br />
            this.meioContatoCollection = meioContatoCollection;<br />
        }<br />
    <br />
        @Override<br />
        public int hashCode() {<br />
            int hash = 0;<br />
            hash += (codigo != null ? codigo.hashCode() : 0);<br />
            return hash;<br />
        }<br />
    <br />
        @Override<br />
        public boolean equals(Object object) {<br />
            // TODO: Warning - this method won't work in the case the id fields are not set<br />
            if (!(object instanceof Pessoa)) {<br />
                return false;<br />
            }<br />
            Pessoa other = (Pessoa) object;<br />
            if ((this.codigo == null && other.codigo != null) || (this.codigo != null && !this.codigo.equals(other.codigo))) {<br />
                return false;<br />
            }<br />
            return true;<br />
        }<br />
    <br />
        @Override<br />
        public String toString() {<br />
            return "br.teste.app.entidades.Pessoa[codigo=" + codigo + "]";<br />
        }<br />
    <br />
    }<br />
    <br />
    <br />
    package br.teste.app.entidades;<br />
    <br />
    import java.io.Serializable;<br />
    import javax.persistence.Column;<br />
    import javax.persistence.Entity;<br />
    import javax.persistence.Id;<br />
    import javax.persistence.JoinColumn;<br />
    import javax.persistence.ManyToOne;<br />
    import javax.persistence.NamedQueries;<br />
    import javax.persistence.NamedQuery;<br />
    import javax.persistence.Table;<br />
    <br />
    /**<br />
    *<br />
    * @author kurumin<br />
    */<br />
    @Entity<br />
    @Table(name = "MEIO_CONTATO")<br />
    @NamedQueries({@NamedQuery(name = "MeioContato.findByMeioContato", query = "SELECT m FROM MeioContato m WHERE m.meioContato = :meioContato"), @NamedQuery(name = "MeioContato.findByTipo", query = "SELECT m FROM MeioContato m WHERE m.tipo = :tipo"), @NamedQuery(name = "MeioContato.findByResponsavel", query = "SELECT m FROM MeioContato m WHERE m.responsavel = :responsavel"), @NamedQuery(name = "MeioContato.findByDescricao", query = "SELECT m FROM MeioContato m WHERE m.descricao = :descricao"), @NamedQuery(name = "MeioContato.findBySetor", query = "SELECT m FROM MeioContato m WHERE m.setor = :setor")})<br />
    public class MeioContato implements Serializable {<br />
        private static final long serialVersionUID = 1L;<br />
        @Column(name = "MEIO_CONTATO", nullable = false)<br />
        private String meioContato;<br />
        @Column(name = "TIPO", nullable = false)<br />
        private String tipo;<br />
        @Column(name = "RESPONSAVEL")<br />
        private String responsavel;<br />
        @Id<br />
        @Column(name = "DESCRICAO", nullable = false)<br />
        private String descricao;<br />
        @Column(name = "SETOR")<br />
        private String setor;<br />
        @JoinColumn(name = "PESSOA_CODG", referencedColumnName = "CODIGO")<br />
        @ManyToOne<br />
        private Pessoa pessoaCodg;<br />
    <br />
        public MeioContato() {<br />
        }<br />
    <br />
        public MeioContato(String tipo, String meioContato, String setor, String resposavel, String descricao) {<br />
            this.descricao = descricao;<br />
            this.meioContato = meioContato;<br />
            this.tipo = tipo;<br />
            this.responsavel = resposavel;<br />
            this.setor = setor;<br />
        }<br />
    <br />
        public String getMeioContato() {<br />
            return meioContato;<br />
        }<br />
    <br />
        public void setMeioContato(String meioContato) {<br />
            this.meioContato = meioContato;<br />
        }<br />
    <br />
        public String getTipo() {<br />
            return tipo;<br />
        }<br />
    <br />
        public void setTipo(String tipo) {<br />
            this.tipo = tipo;<br />
        }<br />
    <br />
        public String getResponsavel() {<br />
            return responsavel;<br />
        }<br />
    <br />
        public void setResponsavel(String responsavel) {<br />
            this.responsavel = responsavel;<br />
        }<br />
    <br />
        public String getDescricao() {<br />
            return descricao;<br />
        }<br />
    <br />
        public void setDescricao(String descricao) {<br />
            this.descricao = descricao;<br />
        }<br />
    <br />
        public String getSetor() {<br />
            return setor;<br />
        }<br />
    <br />
        public void setSetor(String setor) {<br />
            this.setor = setor;<br />
        }<br />
    <br />
        public Pessoa getPessoaCodg() {<br />
            return pessoaCodg;<br />
        }<br />
    <br />
        public void setPessoaCodg(Pessoa pessoaCodg) {<br />
            this.pessoaCodg = pessoaCodg;<br />
        }<br />
    <br />
        @Override<br />
        public int hashCode() {<br />
            int hash = 0;<br />
            hash += (descricao != null ? descricao.hashCode() : 0);<br />
            return hash;<br />
        }<br />
    <br />
        @Override<br />
        public boolean equals(Object object) {<br />
            // TODO: Warning - this method won't work in the case the id fields are not set<br />
            if (!(object instanceof MeioContato)) {<br />
                return false;<br />
            }<br />
            MeioContato other = (MeioContato) object;<br />
            if ((this.descricao == null && other.descricao != null) || (this.descricao != null && !this.descricao.equals(other.descricao))) {<br />
                return false;<br />
            }<br />
            return true;<br />
        }<br />
    <br />
        @Override<br />
        public String toString() {<br />
            return "br.teste.app.entidades.MeioContato[descricao=" + descricao + "]";<br />
        }<br />
    <br />
    }<br />
    <br />
    <br />
    <font color="#ff0000">Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.DatabaseException<br />
    Internal Exception: org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544665. violation of PRIMARY or UNIQUE KEY constraint "UNQ_PESSOA_CPF" on table "PESSOA"<br />
    Error Code: 335544665<br />
    Call: INSERT INTO PESSOA (CODIGO, UF, FOTO_LOGOMARCA, APELIDO, TIPO, RG_INSCRICAO, TIPO_PESSOA, NOME, DATA_CADASTRO, ORGAO_EXPEDIDOR, OBSERVACAO, CPF_CNPJ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)<br />
            bind =&gt; [null, null, null, kjkjk, EM, jkjljlj, J, julkjlkjl, null, null, null, jkjkj222]</font><br />
    <br />
    <br />
    <br />
    Another way to call the methods:
    <br />
    <br />
            EmpresaFacadeRemote empresa = (EmpresaFacadeRemote) ic.lookup("br.teste.app.beans.EmpresaFacadeRemote");<br />
            private Pessoa entidadePessoa = new Pessoa(jtfRasaoSocial.getText(), jtfNomeFantasia.getText(),  jtfCpfCnpj.getText(), jtfRgInscEstadual.getText(),"EM",'J');<br />
            empresa.createEmpresa(entidadePessoa,meiosContatoList);<font color="#ff0000">Local Exception Stack:
    Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544347. validation error for column PESSOA_CODG, value "*** null ***"
    Error Code: 335544347
    Call: INSERT INTO MEIO_CONTATO (DESCRICAO, RESPONSAVEL, TIPO, SETOR, MEIO_CONTATO, PESSOA_CODG) VALUES (?, ?, ?, ?, ?, ?)
    bind =&gt; [(74)3611-3308), Jo&atilde;o da Silva, Resid&ecirc;ncial, Compras, Resid&ecirc;ncial, null]
    Query: InsertObjectQuery(br.teste.app.entidades.MeioContato[descricao=(74)3611-3308)])</font>

    Why when you call this method and gives this error, is as provider of persitência were trying to insert the object Pessoa again?!?!
    Note: The object is persisted in the same person now!
        public Pessoa createEmpresa(Pessoa empresa, List<MeioContato> meiosContatoList) {
            this.empresa = empresa;
            this.empresa.setMeioContatoCollection(meiosContatoList);
            em.persist(this.empresa);
            return this.empresa;
    {code}<br /><br /><br /><br /><br /><br />{color:#ff0000}Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.DatabaseException<br /><br />Internal Exception: org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544665. violation of PRIMARY or UNIQUE KEY constraint "PK_PESSOA" on table "PESSOA"<br /><br />Error Code: 335544665<br /><br />Call: INSERT INTO PESSOA (CODIGO, UF, FOTO_LOGOMARCA, APELIDO, TIPO, RG_INSCRICAO, TIPO_PESSOA, NOME, DATA_CADASTRO, ORGAO_EXPEDIDOR, OBSERVACAO, CPF_CNPJ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)<br /><br />        bind =&gt; [68, null, null, lkjlkjlkjl, EM, jljljljljl, J, jjljljl, null, null, null, jljljlk]<br /><br />{color}<br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Migration of Service/Category relationships

    Migration of Service/Category relationships
    We're still using ServiceMigrate with 2006.0.6.  I'm trying to figure out if the relationship between a service and a category are migrated with a service, with a category, or both. 
    My use case is that currently a service is being displayed in two categories.  I want to remove it from one of those categories.  I can do that from either the category or the service to the same effect.  So now that I've removed one of the relationships, can I migrate that to another environment by migrating the category, or do I need to migrate the service? 

    With ServiceMigrate, you can base the extract class on either services or categories. I would go with categories and modify the extract class released in extractclasses.xml as follows:

  • "Capturing drop-frame media into a non-drop frame clip" error message

    I've logged tapes from what will partly be a 3-camera multi-clip project, and have begun to batch capture.
    Logged all but one tape some weeks ago, and captured one tape at the time.
    Went to batch capture the balance, today. First tape capture went fine. On trying to capture the next tape in the batch I'm getting this message as FCP begins the process:
    WARNING: You are about to capture drop-frame media to a non drop-frame clip. If you proceed, you may experience changes in logged in and out points, problems relinking media, or removal of master clip relationships.
    In analyzing the situation, the only reason I can think of for the error message is that some of the reels were logged on a DSR-11 that had been set to NON drop-frame, and for which I didn't have the remote control to change the setting.
    I haven't run into this while capturing other clips, but those may have been captured via a different deck that does only drop-frame.
    So, I'm looking at next steps:
    1: Capture anyway and possibly regret that I did that.
    (One person on another list reported the same problem, that he had ignored it without any obvious complications.)
    2: Relog all the problem clips using my current deck, speeding up the process by using the "go to" window to drive the tape to the existing in and out points and then marking i/o's...
    Or...
    Suggestions?
    Thanks,
    Ted.

    We've been seeing this stupid error message since v3 and it's never mattered in the slightest. It is always incorrect, anyway. The clips are always drop and the sequences are always drop. It's an FCP programming glitch/bug/screwup. Someday they may or may not fix the mechanism that triggers the warning.
    bogiesan

  • Audio Not Syncing After Offline Conversion/Batch Capture from OfflineRT-DV

    WORKFLOW:
    1. Shooting HDV on a Sony HDR-V1U (DF/NDF Timecode setting is AUTO on the camera)
    2. Using the camera to downconvert to DV as I import into FCP 7 (final product will be NTSC DVD).
    3. I first capture and log using the OfflineRT NTSC (Photo JPEG) preset
    4. I make my Edits, and then use Media Manager to create new project and create offline media referenced by duplicated items. (Set sequences to: DV NTSC 48 kHz)
    5. The clips I need are then batch captured using Capture Preset: DV NTSC 48 kHz
    PROBLEMS:
    A. As I'm initiating my batch capture in step #5 above, the following warning is generated:
    WARNING: You are about to capture Drop Frame media from a device currently detecting or configured for Non-Drop Frame media. If you proceed, you may experience changes in logged in and out points, problems relinking media, or removal of master clip relationships.
    B. When I playback my sequence, the in/out points are off by several seconds. (like the media within the clip slid ahead several seconds--to fix it, I would have to slide each clip back)
    QUESTIONS:
    Q1: How can I properly execute my workflow while avoiding the WARNING above and the problem with the in/out points?
    NOTE: The OfflineRT clips in the original project (#3 above) are shown as DF (semicolon in timecode), but the duplicated clips in the DV project (#4 above) are NDF (colon in timecode). I have already tried changing my capture preset to Firewire NTSC NDF, recapturing the clips, and the result is the same.
    Q2: Should the capture preset be the same or different when logging the first (OfflineRT) and second (DV NTSC 48kHz) times?

    Wish I had a simple answer for you, stay tuned, some folks who actually use those cameras will drop by sooner or later.
    TrevorRawson wrote:
    After importing through log and capture I continue to get a pop up when it's done saying that the audio and video frame rates do not line up.
    I'll bet you're shooting with a Canon.
    TrevorRawson wrote:
    I am using a Canon xl2 and a Panasonic DVX100A,
    Ah-HA!
    TrevorRawson wrote:I'm shooting in 24p Advanced with a 2:3:3:2 pull down. The capture settings are set up for FCP's default DV NTSC 24p with Advanced Pulldown, same with my sequence settings. This is my first time shooting in 24pa so I'm a little lost at what to do. Does anyone know the correct settings I should be using?
    so neither camera captures properly? that's odd. We know the Canon is going to give you trouble but the Pani should work.
    Try searching the forum for your camera models, see what comes up. Many different cameras shoot their own versions of various image,frame, and pulldown formats.
    bogiesan

  • Digitizing Pre-Logged Clips: Drop Frame/Non-Drop Frame Discrepency

    I have about 100hrs of DV NTSC footage that has been logged and now I need to capture it.
    Everything seemed good to go:
    • I ctrl+click the clip intended to capture
    • Select 'batch capture' (it initializes)
    • Settings are (apple setting) DV NTSC 48kHz
    • I click okay and I get an error message that reads:
    "WARNING: You are about to capture drop-frame media to a non-drop frame clip. If you proceed, you may experience changes in logged in and out points, problems relinking media, or removal of master clip relationships."
    Now, the setting noted above is set at 29.97 not 30.
    I tried to see if there was anything I could select/deselect in the logged clips and came up dry.
    I made duplicated the apple setting and changed the fps to 30. This yielded no error message but did on the second clip I tried.
    Does anyone have any idea on how I should be troubleshooting this?
    Due to the high volume of footage, and workflow schedule, I'd really rather not screw this up.
    I turn to you my faithful FCP gurus.
    Thanks.
    Ian
    p.s. I'm running FCP v.5.1.4

    Just check your timecode accuracy before you get any further... i.e. does the timecode in the captured clip match the code that's on the tape. If so, you're good to go on... if not, I'd recapture using the proper TC... it's pretty easy if you do it from the tape in the Log and Capture window.
    Jerry

  • Stack Overflow Exception in EJB Explorer

    Hello everyone!
    I have correct working EJB which returns in one method and JPA Entity that have bidirectional relationship with other entity. This relationship is @OneToMany and @ManyToOne on other side and all of the related objects are loaded before the end of the method. This EJB is working correctly when used with other components.
    I have problems testing this method in EJB Explorer utility that is part of the SAP NetWeaver Aplication Server Java. When i start this method it never finishes and later gets an stack overflow error. Trace is here:
    java.lang.RuntimeException: java.lang.StackOverflowError : null
      at java.lang.Class.getMethod0(Class.java:2670)
      at java.lang.Class.getMethod(Class.java:1603)
      at com.sap.ejbexplorer.business.invocation.impl.Structure.fillWith(Structure.java:213)
      at com.sap.ejbexplorer.business.invocation.impl.Structure.fillNestedStructureWith(Structure.java:314)
      at com.sap.ejbexplorer.business.invocation.impl.Structure.fillWith(Structure.java:202)
      at com.sap.ejbexplorer.business.invocation.impl.Structure.fillNestedStructureWith(Structure.java:287)
      at com.sap.ejbexplorer.business.invocation.impl.Structure.fillWith(Structure.java:234)
    Looks like EJB Explorer is trying to expand all returned objects. Then he gets into the unfinished loop because of the bidirectional relationship.
    We are using SAP NetWeaver 7.20 SP04.
    Is this error fixed in new version?
    Is there some configuration that fix this?
    Thank you for any response.

    Hi,
    is it just for the presence of the JUnit extension, or do you use this class in your Unit testing ?
    Frank
    Ps.: The JDeveloper 11 forum is JDeveloper and OC4J 11g Technology Preview

  • Multiple BPs for an employee in CRM

    Hi,
    We have ECC-HR (6.0) integaration with CRM (6.0)for employee data . We have triggered initial download and all the Organizational units, positions and employees downloaded and relationships created without any issues.  Now a days we are getting some issues like some times the CP-BP relationship isgetting deleted and when we try to download the employee once again into CRM through PFAL(update mode) transaction in ECC, a new BP is getting created that is linked to the CP in CRM. By this we are missing all the previous transactions made by this employee in CRM (as earlier the employee was linked to other BP and now that is no more valid).
    Please let me know how can we overcome this situation? What are the cases where CP-BP relationships will be deleted in CRM?
    Any help will be highly appreciated.
    Thanks,
    Rajinikanth G

    Hi,
    the issue of deleted CP-BP relationship may be related to a low level of support packages of component SAP_ABA. You may keep your system up to date by istalling available support packages or check related notes of note 934372 and apply available correction instructions.
    If new BPs already have been created you have to remove the CP-BP relationship from table HRP1001 using report RHRHDL00 by specifying the id of the CP and the relationship A/B207 (not sure if A or B).
    After this you have to find the BP which has been created originally (searching by name) and use a report to restore the link from theCP to the this BP - the report has to be created from a note linked to note 934372 (short text mentioning ...help reports). The new BP created on error can then be deleted .
    Hope  your issue can be solved,
    Michael

  • DV NTSD drop-frame vs. non-drop-frame??

    My impression has always been that DV NTSC is non-drop frame. I'm having to capture a 100 hours of DV tapes from a Sony WV-DR7 deck. FCP capture is giving me this warning:
    "You are about to capture Non-Drop Frame media from a device currently detecting or configured for Drop Frame media. If you proceed, you may experience changes in logged in and out points, problems relinking media, or removal of master clip relationships."
    The Sony is all in Japanese, and the rough translation manual does not mention drop frame \ non-drop frame setting choices on the deck.
    Would anyone have any suggestions or recommendations?
    Ben

    Sorry to be confusing~~~~
    What I meant was, since I wasn't sure if the VTR you are using actually shows the timecode window, or just a timecode counter (the Sony DSR-11's display does not show the colon/semicolon difference in the display that is supered on the non-digital video outs), I thought the quickest way to assess what flavor of TC you had was to play the tape and use "Capture Now" to capture a few seconds. Then you can look in the bin, check the media start column and see if there are semi-colons or colons. This would be helpful particularly if FCP is balking at capturing from your logged marks.
    The other thing I was talking about was a case where I had been given DVCam copies of camera masters, to use for a rough cut. Because these tapes were work prints, they used old DVCam tapes. One of the tapes had originally had DF material on it. When the tape op made the workprint, he started recording the new NDF material about 10 seconds into the tape, he therefore left 10 seconds of DF bars at the head of the reel (the old material). I put the tape in a DSR-11, fast wound up to picture, and started logging. When I was at the end of the reel, I hit rewind on the machine so it would rewind while I was clearing up spelling errors, etc. The machine backed all the way to head of the tape, into the DF area.
    So when I hit batch capture, the machine reported back to FCP that it had a tape with the correct name loaded, but the time code was in the incorrect format - the message you received. It took a while to figure it out, but when I wound the tape forward, so that it was in the picture portion of the reel, the machine was then outputting the code that FCP was expecting. So by "parking" the deck in the picture portion of the tape, it would cue correctly from the logged point.
    Hope this explains it. hope you have a simple solution, too.
    Message was edited by: Meg The Dog to fix typo

  • Drop Frame/Non-Drop Frame Warning

    Hi,
    First off, thank you to the experienced people out there who take the time to explain things and answer these questions.
    About the following warning:
    Warning: You are about to capture drop-frame media to a non-drop frame clip. If you proceed, you may experience changes in logged in and out points, problems relinking media, or removal of master clip relationships.
    I logged about 40 clips by entering In and Out points (from a piece of paper), turned on my camera, went to Batch Capture, and it gave me this warning. I read a little bit about timecode (I know little about it) and realized that I didn't use semi-colons when entering my timecode in the Log and Capture window. Apparently this is important; I have a Panasonic GS500.
    I captured anyway, and I have all the video I want; the "handles" inherent in the In and Out points I used should accomodate even several seconds of any timecode discrepancy.
    My question: When I am done editing and go to recapture my sequences at full DV quality, will there be a difference between the In and Out points of my clips and the tape? Have I mis-captured media files in some way? How can I tell if the Media Start and Media End information isn't out of sync?
    Cyrus

    Just check your timecode accuracy before you get any further... i.e. does the timecode in the captured clip match the code that's on the tape. If so, you're good to go on... if not, I'd recapture using the proper TC... it's pretty easy if you do it from the tape in the Log and Capture window.
    Jerry

Maybe you are looking for

  • How do I add to "properties" of an MP3 file in Windows so iPod will accept?

    I posted a problem yesterday, which I was clueless about. Today I know what the problem is, but don't know how to fix it. I have 30 MP3 files in a playlist, all from an identical album. I can play every file on my computer through iTunes with no prob

  • Analytical function SUM() OVER (PARTITION BY ) in Crosstab

    I am trying to resolve this from a very long time. I have an amount column that has to be grouped on Year, but all the other columns grouped by month. I am trying to achieve this using analytic function SUM(Case when (Condition1 and Condition2) then

  • HR table/infotype query

    hi.. i have the value for POSITION (PLANS).... using 'plans'....i need to get its 'werks', 'persg', 'persk'.... from which table/infotype can i get these? regards balaji.

  • Upgrade to 12.1.2.0 now ?

    Hi all, I have developed an adf application with JDeveloper 11.1.2.4.0 and I want to move it to production environment. I also want to upgrade to 12.1.2.0 and use some new components like Panel SpringBoard etc.  But I have some doubts because I have

  • Problem with a script

    I can be reached at [email protected] I had a question for you to see if you can solve. I have a script below I am trying to run in Oracle 9i SQL+ with SYSTEM/MANAGER privileges. Is the script look complete to you? For some reason I get insuffici