hi, i have problem trying to create a many-to-many relationship.
i have 2 classes:
Code:
public class Venue {
private Integer venueId;
private String venueType;
private String venueName;
private Set Club;
// getter & setter
// add & remove Club
Code:
public class Club{
private Integer clubId;
private String clubName;
private Set Venue
// getter & setter, add & remove
my hbm file is as follow
Venue.hbm.xmlCode:
...
<set name="venueClubRelationship" table="club_venue" cascade="save-update">
<key column="venueId"/>
<many-to-many class="Club"/>
</set>
...
Club.hbm.xmlCode:
...
<set name="clubVenueRelationship" table="club_venue" cascade="save-update">
<key column="clubId"/>
<many-to-many class="Venue"/>
</set>
...
when i try to test this code by running this following code:
Code:
...
Club club= (Club)new ClubDAO().getClubById(1);
Venue v = (Venue)new VenueDAO().getVenueById(7);
club.addVenue(v);
boolean success = new ClubDAO().save(club);
System.out.println("success: " + success);
...
it gives me this error:
Code:
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.persister.collection.AbstractCollectionPersister.insertRows(AbstractCollectionPersister.java:1394)
at org.hibernate.action.CollectionUpdateAction.execute(CollectionUpdateAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
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 com.jjcs.fas.dbms.organisation.OrganisationDAO.save(OrganisationDAO.java:172)
at com.jjcs.fas.dbms.organisation.Test_OrganisationDAO.<init>(Test_OrganisationDAO.java:43)
at com.jjcs.fas.dbms.organisation.Test_OrganisationDAO.main(Test_OrganisationDAO.java:22)
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot insert the value NULL into column 'venueId', table 'DB_DBMS.dbo.club_venue'; column does not allow nulls. INSERT fails.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeUpdateInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeUpdate(Unknown Source)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.collection.AbstractCollectionPersister.insertRows(AbstractCollectionPersister.java:1367)
... 10 more
how should i handle this?
I know the problem is because the field is not set as "allow-null" but how should I do that?
Could someone please explain me how should I fix this issue?
Thank you very much![/code]