-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: why i cannot insert into my table?
PostPosted: Mon Nov 06, 2006 4:57 pm 
Newbie

Joined: Tue Oct 31, 2006 5:19 am
Posts: 11
hi all,
i have tables
Person: PersonID(PK), name
PersonProject:PPID(PK), PersonID(FK), ProjectID(FK), roleName
Project:ProjectID(PK), name.

Person and Project to PersonProject is one to many

when i try to addPersonProject(Person aPerson,Project aProject, String roleName){
...
PersonProject pp = new PersonProject();
pp.setPersonID(aPerson.getID());
pp.setProjectID(aProject.getProjectID);
pp.setRoleName(roleName);
session.save(pp);
...
}

by save comes illegalargument caused by getter in Project. by i see under debugg the getter has the value of projectID.

what did i do wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 4:50 am 
Newbie

Joined: Tue Oct 31, 2006 5:19 am
Posts: 11
help!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 5:56 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Ting wrote:
help!!

http://www.hibernate.org/ForumMailingli ... AskForHelp

Please provide more information (mappigns and stuff)

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 6:16 am 
Newbie

Joined: Tue Oct 31, 2006 5:19 am
Posts: 11
thank you very much for your answer! here is the detail of my stuff.
tables:
Person: PersonID(PK), surname ,firstname,tel,email
PersonProject:PPID(PK), PersonID(FK), ProjectID(FK), roleName
Project:ProjectID(PK), name description

Java classes:
class Person {
private Long id;
private String surname;
private String firstname;
private String email;
private String telNr;
private Set persProj = new HashSet();
getter und setters
.....}
public class PersonProject {
private Long id;
private Long personID;
private Long projectID;
private String roleName;

public PersonProject(){};
getter and setters
.....}
public class Project {
private Long id;
private String name;
private String description;
private Set subProjects = new HashSet();
private Project superProject;
private Set persProj = new HashSet();

public Project(){};
getter and setters
.....}

hbm.xmls:
Person:
<class name="mapping.Person" table="TMP_PERSON">
<id name="id" column="PERSONID">
<generator class="sequence"/>
</id>
<property name="telNr" column="TEL"/>
<property name="surname" column="SURNAME"/>
<property name="firstname" column="FIRSTNAME"/>
<property name="email" column="EMAIL"/>

<set name="persProj" inverse="true" cascade="all">
<key column="PERSONID"/>
<one-to-many class="mapping.PersonProject"/>

</set>
PersonProject:
class name="mapping.PersonProject" table="TMP_PERS_PROJ">
<id name="id" column="PERSPROJID">
<generator class="sequence"/>
</id>

<property name="roleName" column="ROLENAME"/>

<many-to-one name="projectID" column="PROJECTID" class="mapping.Project"/>
<many-to-one name="personID" column="PERSONID" class="mapping.Person"/>

Project:
<class name="mapping.Project" table="TMP_PROJECT">
<id name="id" column="PROJECTID">
<generator class="sequence"/>
</id>
<property name="name" column="NAME"/>
<property name="description" column="DESCRIPTION"/>
<many-to-one name="superProject" column="SUPERPROJECTID" />
<set name="subProjects" cascade="all" inverse="true">
<key column="SUPERPROJECTID"/>
<one-to-many class="mapping.Project"/>
</set>
<set name="persProj" inverse ="true" cascade="all">
<key column="PROJECTID"/>
<one-to-many class="mapping.PersonProject"/>
</set>

</class>
my method to insert into table Pers_Proj:
protected void addPersonToProject(Person person, Project project,String roleName) {

Session session = null;
Transaction transaction = null;
session = sessionFactory.openSession();
transaction = session.beginTransaction();
PersonProject pp = new PersonProject();
pp.setPersonID(person.getId());
pp.setProjectID(project.getId());
pp.setRoleName(roleName);

session.save(pp);
session.getTransaction().commit();
session.close();
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 11:18 am 
Newbie

Joined: Thu Nov 02, 2006 8:41 am
Posts: 13
Location: Argentina
I think you have a concept error.


when you map classes you have to forgot from the relational model, because you are setting IDs with the setters methods, no no, you have to set Objects!!!.


Your Class :

public class PersonProject {
private Long id;
private Long personID;
private Long projectID;
private String roleName;

why you have the projectID???????? thats no better you have your

private Project project;

with the setter method?

setProject(Project proyect);

and then map the class

PersonProject
with the one-to-many clause


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 11:42 am 
Newbie

Joined: Tue Oct 31, 2006 5:19 am
Posts: 11
thanks! I have hust changed the PersonID an ProjectID in my PersonProject class, but now comes the other error:-(
new code:
private Person person;
private Project project;
with getter and setters
****************
new mapping:
<many-to-one name="project" column="PROJECTID" class="mapping.Project"/>
<many-to-one name="person" column="PERSONID" class="mapping.Person"/>
**********************
16:22:36,911 DEBUG JDBCExceptionReporter:63 - Could not execute JDBC batch update [insert into TMP_PERS_PROJ (ROLENAME, PROJECTID, PERSONID, PERSPROJID) values (?, ?, ?, ?)]
com.sap.dbtech.jdbc.exceptions.BatchUpdateExceptionSapDB: [-9041]: System error: BD Index not accessible(input position 2)
at com.sap.dbtech.jdbc.CallableStatementSapDB.executeBatch(CallableStatementSapDB.java:608)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at dao.AccessMethods.addPersonToProject(AccessMethods.java:81)
at dao.testMain.main(testMain.java:51)
16:22:36,911 WARN JDBCExceptionReporter:71 - SQL Error: -9041, SQLState: S9041
16:22:36,911 ERROR JDBCExceptionReporter:72 - [-9041]: System error: BD Index not accessible(input position 2)
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at dao.AccessMethods.addPersonToProject(AccessMethods.java:81)
at dao.testMain.main(testMain.java:51)
Caused by: com.sap.dbtech.jdbc.exceptions.BatchUpdateExceptionSapDB: [-9041]: System error: BD Index not accessible(input position 2)
at com.sap.dbtech.jdbc.CallableStatementSapDB.executeBatch(CallableStatementSapDB.java:608)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
... 9 more
16:22:36,911 ERROR AbstractFlushingEventListener:301 - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 11:53 am 
Newbie

Joined: Tue Oct 31, 2006 5:19 am
Posts: 11
thanks a lot for the answer.
the insert works now. the error before is because that i stopped my database without a normal shoutdown and indexes became "not accessible" in SAP DB.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.