Results 1 to 15 of 15
  1. #1
    halyal is offline Member
    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0

    Default help me with persistence

    i have two classes AAccMst and AAccgrpMst
    data is store in sql server
    the relation is grpid which is interger field

    Java Code:
     public class AAccMst implements Serializable {
        private static final long serialVersionUID = 1L;
        @ManyToOne(fetch=FetchType.LAZY)
        @JoinColumn(name="grpid",referencedColumnName = "grpid")
        private AAccgrpMst accgrp;
        public AAccgrpMst getAccgrp() {
            return accgrp;
        }
       public void setAccgrp(AAccgrpMst grp) {
            this.accgrp = grp;
        }
    //    @Basic(optional = false)
    //    @Column(name = "grpid", nullable = false)
        private int grpid=0;
    
        public int getGrpid() {
            return grpid;
        }
    
        public void setGrpid(int grpid) {
            this.grpid = grpid;
        }
    
        @Id
        @GeneratedValue(strategy=GenerationType.IDENTITY)
        @Basic(optional = false)
        @Column(name = "accid", nullable = false)
        private Long accid;
        @Basic(optional = false)
        @Column(name = "acccd", nullable = false, length = 10)
        private String acccd="";
        @Basic(optional = false)


    Java Code:
    public class AAccgrpMst implements Serializable {
        private static final long serialVersionUID = 1L;
        @OneToMany(cascade=CascadeType.ALL,mappedBy = "accgrp")
        @MapKey(name="grpid")
        @OrderBy(value="accname")
        private Collection<AAccMst> grpaccs;
    
        public void addAccmst(AAccMst acc)
        {
            this.grpaccs.add(acc);
            if (acc.getAccgrp() != this)
            {
                acc.setAccgrp(this);
            }
        }
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Basic(optional = false)
        @Column(name = "grpid", nullable = false)
        private Integer grpid;
        @Basic(optional = false)
        @Column(name = "grpname", nullable = false, length = 40)
        private String grpname="";
        @Basic(optional = false)
    everthing works fine for retrieving data but when i try to add new AAccMst to AAccgrpMst the resulting sql code generated contains two grpid fieds and hence the insert fails.

    The source code is attached in zip format.
    Rajesh
    Attached Files Attached Files

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default

    Presumably grpid is the primary key of AAccgrpMst, so why not make it simply id?
    Normally, naming-wise, the id of an object (ie the generated primary key) is called id, and the foreign key is called <class>_id. This helps prevent such name clashes.

    I suspect there's another way around it (I think there's a switch for prefixing tablenames to the columns in a query, for example). To be honest, I'm surprised it doesn't do that....I would swear Hibernate did.

  3. #3
    halyal is offline Member
    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0

    Default the database is already present how to change the id

    already have wasted 2 days on this
    the database is already present how to change the id in the class
    there is another VFP application using this db.
    will this crash the already bound jtables.
    Last edited by halyal; 09-02-2010 at 09:40 AM.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default

    What persistence stuff are you using?

  5. #5
    halyal is offline Member
    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0

    Default

    TopLink - EclipseLink(JPA 2.0)

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default

    And is there documentation on controlling how it builds its queries?

    Have you an example of the INSERT it generates?

    I'm trying to figure out exactly where it's going wrong.

  7. #7
    halyal is offline Member
    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0

    Default this is the actual error message

    [EL Warning]: 2010-09-02 17:01:28.861--UnitOfWork(14456678)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.DatabaseExcepti on
    Internal Exception: java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Column name 'grpid' appears more than once in the result column list.
    Error Code: 264
    Call: INSERT INTO a_acc_mst (accname, acccd, userid, panno, address1, address2, address3, renewdate, note, phoneno, stateid, compid, updatedon, closedate, cityid, creditlimit, tdsrate, taxno1, GRPID, regionid, opendate, prefix, taxno2, grpid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    bind => [NEW ACCOUNT, , 0, , , , , 2010-09-02 17:01:28.541, , , 0, 0, 2010-09-02 17:01:28.541, 2010-09-02 17:01:28.541, 0, 0, 0, , 0, 0, 2010-09-02 17:01:28.541, , , 58]
    Query: InsertObjectQuery(mytable.AAccMst[accid=null])
    Exception in thread "AWT-EventQueue-0" javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.DatabaseExcepti on
    Internal Exception: java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Column name 'grpid' appears more than once in the result column list.
    Error Code: 264 (My comment this error is generated when same field is repeated in insert)
    Call: INSERT INTO a_acc_mst (accname, acccd, userid, panno, address1, address2, address3, renewdate, note, phoneno, stateid, compid, updatedon, closedate, cityid, creditlimit, tdsrate, taxno1, GRPID, regionid, opendate, prefix, taxno2, grpid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    bind => [NEW ACCOUNT, , 0, , , , , 2010-09-02 17:01:28.541, , , 0, 0, 2010-09-02 17:01:28.541, 2010-09-02 17:01:28.541, 0, 0, 0, , 0, 0, 2010-09-02 17:01:28.541, , , 58]
    Query: InsertObjectQuery(mytable.AAccMst[accid=null])

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default

    What happens if you remove the local grpid from AAccMst?

    Looks like (even with the removal of the annotations) that it's still trying to use it.
    You don't actually need it anyway, so there's no point it being in there.

  9. #9
    halyal is offline Member
    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0

    Default have to remove some more code with it still error exists

    have to remove some more code with it
    like getter setter
    the code compiles (sorry the project builds) but exception is thrown at the start of application loading data

    [EL Info]: 2010-09-02 19:40:12.038--ServerSession(33539718)--EclipseLink, version: Eclipse Persistence Services - 2.0.2.v20100323-r6872
    [EL Severe]: 2010-09-02 19:40:14.452--ServerSession(33539718)--Local Exception Stack:
    Exception [EclipseLink-8030] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.JPQLException
    Exception Description: Error compiling the query [AAccMst.findByGrpid: SELECT a FROM AAccMst a WHERE a.grpid = :grpid], line 1, column 32: unknown state or association field [grpid] of class [mytable.AAccMst].
    Exception in thread "AWT-EventQueue-0" javax.persistence.PersistenceException: Exception [EclipseLink-8030] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.JPQLException
    Exception Description: Error compiling the query [AAccMst.findByGrpid: SELECT a FROM AAccMst a WHERE a.grpid = :grpid], line 1, column 32: unknown state or association field [grpid] of class [mytable.AAccMst].
    at org.eclipse.persistence.internal.jpa.EntityManager SetupImpl.deploy(EntityManagerSetupImpl.java:397)
    at org.eclipse.persistence.internal.jpa.EntityManager FactoryImpl.getServerSession(EntityManagerFactoryI mpl.java:151)
    at org.eclipse.persistence.internal.jpa.EntityManager FactoryImpl.createEntityManagerImpl(EntityManagerF actoryImpl.java:207)
    at org.eclipse.persistence.internal.jpa.EntityManager FactoryImpl.createEntityManager(EntityManagerFacto ryImpl.java:195)
    at org.eclipse.persistence.exceptions.JPQLException.u nknownAttribute(JPQLException.java:457)
    at org.eclipse.persistence.internal.jpa.parsing.DotNo de.validate(DotNode.java:78)
    at org.eclipse.persistence.internal.jpa.parsing.Node. validate(Node.java:91)
    at org.eclipse.persistence.internal.jpa.parsing.Binar yOperatorNode.validate(BinaryOperatorNode.java:34)
    at org.eclipse.persistence.internal.jpa.parsing.Equal sNode.validate(EqualsNode.java:41)
    at org.eclipse.persistence.internal.jpa.parsing.Where Node.validate(WhereNode.java:34)
    at org.eclipse.persistence.internal.jpa.parsing.Parse Tree.validate(ParseTree.java:211)
    at org.eclipse.persistence.internal.jpa.parsing.Parse Tree.validate(ParseTree.java:187)
    at org.eclipse.persistence.internal.jpa.parsing.Parse Tree.validate(ParseTree.java:177)
    at org.eclipse.persistence.internal.jpa.parsing.JPQLP arseTree.populateReadQueryInternal(JPQLParseTree.j ava:110)
    at org.eclipse.persistence.internal.jpa.parsing.JPQLP arseTree.populateQuery(JPQLParseTree.java:84)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl. buildEJBQLDatabaseQuery(EJBQueryImpl.java:202)
    at org.eclipse.persistence.internal.jpa.JPAQuery.proc essJPQLQuery(JPAQuery.java:106)
    at org.eclipse.persistence.internal.jpa.JPAQuery.prep are(JPAQuery.java:90)
    at org.eclipse.persistence.queries.DatabaseQuery.chec kPrepare(DatabaseQuery.java:464)
    at org.eclipse.persistence.queries.DatabaseQuery.chec kPrepare(DatabaseQuery.java:430)
    at mytable.mainframe.initComponents(mainframe.java:51 )
    at mytable.mainframe.<init>(mainframe.java:31)
    at mytable.mainframe$7.run(mainframe.java:309)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 597)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
    at org.eclipse.persistence.internal.sessions.Abstract Session.processJPAQueries(AbstractSession.java:174 7)
    at org.eclipse.persistence.internal.sessions.Database SessionImpl.initializeDescriptors(DatabaseSessionI mpl.java:409)
    at org.eclipse.persistence.internal.sessions.Database SessionImpl.postConnectDatasource(DatabaseSessionI mpl.java:671)
    at org.eclipse.persistence.internal.sessions.Database SessionImpl.loginAndDetectDatasource(DatabaseSessi onImpl.java:620)
    at org.eclipse.persistence.internal.jpa.EntityManager FactoryProvider.login(EntityManagerFactoryProvider .java:228)
    at org.eclipse.persistence.internal.jpa.EntityManager SetupImpl.deploy(EntityManagerSetupImpl.java:369)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)
    Caused by: Exception [EclipseLink-8030] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.JPQLException
    Exception Description: Error compiling the query [AAccMst.findByGrpid: SELECT a FROM AAccMst a WHERE a.grpid = :grpid], line 1, column 32: unknown state or association field [grpid] of class [mytable.AAccMst].
    at org.eclipse.persistence.exceptions.JPQLException.u nknownAttribute(JPQLException.java:457)
    at org.eclipse.persistence.internal.jpa.parsing.DotNo de.validate(DotNode.java:78)
    at org.eclipse.persistence.internal.jpa.parsing.Node. validate(Node.java:91)
    at org.eclipse.persistence.internal.jpa.parsing.Binar yOperatorNode.validate(BinaryOperatorNode.java:34)
    at org.eclipse.persistence.internal.jpa.EntityManager FactoryImpl.getServerSession(EntityManagerFactoryI mpl.java:151)
    at org.eclipse.persistence.internal.jpa.EntityManager FactoryImpl.createEntityManagerImpl(EntityManagerF actoryImpl.java:207)
    at org.eclipse.persistence.internal.jpa.EntityManager FactoryImpl.createEntityManager(EntityManagerFacto ryImpl.java:195)
    at mytable.mainframe.initComponents(mainframe.java:51 )
    at mytable.mainframe.<init>(mainframe.java:31)
    at mytable.mainframe$7.run(mainframe.java:309)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 597)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
    at org.eclipse.persistence.internal.jpa.parsing.Equal sNode.validate(EqualsNode.java:41)
    at org.eclipse.persistence.internal.jpa.parsing.Where Node.validate(WhereNode.java:34)
    at org.eclipse.persistence.internal.jpa.parsing.Parse Tree.validate(ParseTree.java:211)
    at org.eclipse.persistence.internal.jpa.parsing.Parse Tree.validate(ParseTree.java:187)
    at org.eclipse.persistence.internal.jpa.parsing.Parse Tree.validate(ParseTree.java:177)
    at org.eclipse.persistence.internal.jpa.parsing.JPQLP arseTree.populateReadQueryInternal(JPQLParseTree.j ava:110)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)

    at org.eclipse.persistence.internal.jpa.parsing.JPQLP arseTree.populateQuery(JPQLParseTree.java:84)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl. buildEJBQLDatabaseQuery(EJBQueryImpl.java:202)
    at org.eclipse.persistence.internal.jpa.JPAQuery.proc essJPQLQuery(JPAQuery.java:106)
    at org.eclipse.persistence.internal.jpa.JPAQuery.prep are(JPAQuery.java:90)
    at org.eclipse.persistence.queries.DatabaseQuery.chec kPrepare(DatabaseQuery.java:464)
    at org.eclipse.persistence.queries.DatabaseQuery.chec kPrepare(DatabaseQuery.java:430)
    at org.eclipse.persistence.internal.sessions.Abstract Session.processJPAQueries(AbstractSession.java:174 7)
    at org.eclipse.persistence.internal.sessions.Database SessionImpl.initializeDescriptors(DatabaseSessionI mpl.java:409)
    at org.eclipse.persistence.internal.sessions.Database SessionImpl.postConnectDatasource(DatabaseSessionI mpl.java:671)
    at org.eclipse.persistence.internal.sessions.Database SessionImpl.loginAndDetectDatasource(DatabaseSessi onImpl.java:620)
    at org.eclipse.persistence.internal.jpa.EntityManager FactoryProvider.login(EntityManagerFactoryProvider .java:228)
    at org.eclipse.persistence.internal.jpa.EntityManager SetupImpl.deploy(EntityManagerSetupImpl.java:369)
    ... 14 more
    BUILD SUCCESSFUL (total time: 9 seconds)

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default

    This is probably too complex a problem to solve here, and I run the risk of giving seriously duff info based on a total lack of knowledge of your system or setup.

  11. #11
    halyal is offline Member
    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0

    Default

    if you need the project code i am ready to send it its just single form for testing.
    if not could you please direct me where i can find some help
    i am really going mad with this problem

  12. #12
    halyal is offline Member
    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0

    Default

    the problem has been solved
    the culprit was named query AAccMst.findByGrpid which was automatically generated
    after removing it everything seems working fine.

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default

    I was going to suggest that, but that's when I realised without knowing your system that would likely be bad advice.
    :)

  14. #14
    halyal is offline Member
    Join Date
    Aug 2010
    Posts
    14
    Rep Power
    0

    Default

    if i had not solved this problem i would have left java forever.

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

Similar Threads

  1. Persistence technology
    By Hugo in forum AWT / Swing
    Replies: 6
    Last Post: 05-09-2010, 12:08 PM
  2. problem with Persistence.createEntityManagerFactory
    By jordanthompson in forum Advanced Java
    Replies: 7
    Last Post: 12-24-2009, 12:38 PM
  3. Name persistence is not bound in this Context
    By tascoa in forum Java Servlet
    Replies: 1
    Last Post: 12-15-2009, 10:01 PM
  4. Hibernate Java Persistence
    By JavaBean in forum Java Tutorial
    Replies: 0
    Last Post: 09-22-2007, 10:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •