Results 1 to 15 of 15
Thread: help me with persistence
- 09-02-2010, 07:57 AM #1
Member
- Join Date
- Aug 2010
- Posts
- 14
- Rep Power
- 0
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)
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.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)
The source code is attached in zip format.
Rajesh
- 09-02-2010, 09:07 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 09-02-2010, 09:30 AM #3
Member
- Join Date
- Aug 2010
- Posts
- 14
- Rep Power
- 0
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.
- 09-02-2010, 09:44 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
What persistence stuff are you using?
- 09-02-2010, 09:54 AM #5
Member
- Join Date
- Aug 2010
- Posts
- 14
- Rep Power
- 0
TopLink - EclipseLink(JPA 2.0)
- 09-02-2010, 10:51 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 09-02-2010, 12:44 PM #7
Member
- Join Date
- Aug 2010
- Posts
- 14
- Rep Power
- 0
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])
- 09-02-2010, 01:51 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 09-02-2010, 03:22 PM #9
Member
- Join Date
- Aug 2010
- Posts
- 14
- Rep Power
- 0
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)
- 09-02-2010, 03:31 PM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 09-02-2010, 06:53 PM #11
Member
- Join Date
- Aug 2010
- Posts
- 14
- Rep Power
- 0
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
- 09-03-2010, 05:09 AM #12
Member
- Join Date
- Aug 2010
- Posts
- 14
- Rep Power
- 0
the problem has been solved
the culprit was named query AAccMst.findByGrpid which was automatically generated
after removing it everything seems working fine.
- 09-03-2010, 08:46 AM #13
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
I was going to suggest that, but that's when I realised without knowing your system that would likely be bad advice.
:)
- 09-04-2010, 08:24 AM #14
Member
- Join Date
- Aug 2010
- Posts
- 14
- Rep Power
- 0
if i had not solved this problem i would have left java forever.
- 09-04-2010, 10:20 AM #15
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Similar Threads
-
Persistence technology
By Hugo in forum AWT / SwingReplies: 6Last Post: 05-09-2010, 12:08 PM -
problem with Persistence.createEntityManagerFactory
By jordanthompson in forum Advanced JavaReplies: 7Last Post: 12-24-2009, 12:38 PM -
Name persistence is not bound in this Context
By tascoa in forum Java ServletReplies: 1Last Post: 12-15-2009, 10:01 PM -
Hibernate Java Persistence
By JavaBean in forum Java TutorialReplies: 0Last Post: 09-22-2007, 10:02 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks