Hi all,
I have slightly changed/played with auction example in 2.1
Here are my files:
<class name="org.hibernate.auction.AuctionItem" dynamic-update="true">
<id name="id">
<generator class="native"/>
</id>
<property name="description"/>
<property name="ends"/>
<property name="condition"/>
<many-to-one name="seller" not-null="true"/>
<many-to-one name="successfulBid" outer-join="false"/>
<bag name="bids" lazy="true" inverse="true" cascade="all-delete-orphan">
<key column="item"/>
<one-to-many class="org.hibernate.auction.Bid"/>
</bag>
</class>
<class name="org.hibernate.auction.Bid">
<id name="id">
<generator class="native"/>
</id>
<property name="amount" not-null="true"/>
<property name="datetime" not-null="true"/>
<many-to-one name="bidder" not-null="true"/>
<many-to-one name="item" not-null="true"/>
</class>
<class name="org.hibernate.auction.User" table="AuctionUser" proxy="org.hibernate.auction.User">
<id name="id">
<generator class="native"/>
</id>
<property name="userName" not-null="true"/>
<property name="password"/>
<property name="email"/>
<property name="firstName"/>
<property name="lastName"/>
<bag name="bids" lazy="false" inverse="true" cascade="all-delete-orphan">
<key column="bidder"/>
<one-to-many class="org.hibernate.auction.Bid"/>
</bag>
<bag name="auctions" lazy="true" inverse="true" cascade="all-delete-orphan">
<key column="seller"/>
<one-to-many class="org.hibernate.auction.AuctionItem"/>
</bag>
</class>
and my Main:
final Main test = new Main();
Configuration cfg = new Configuration()
.addClass(AuctionItem.class)
.addClass(Bid.class)
.addClass(User.class)
.setProperty(Environment.HBM2DDL_AUTO, "create");
cfg.setProperty("hibernate.show_sql", "true");
test.factory = cfg.buildSessionFactory();
test.createTestAuctions();
List newAuc = new ArrayList();
AuctionItem ai = new AuctionItem();
ai.setDescription("ai descr");
ai.setSeller(mainSeller);
ai.setBids(new ArrayList());
newAuc.add(ai);
mainSeller.setAuctions(newAuc);
Bid bi = new Bid();
bi.setDatetime(new Date());
bi.setBidder(mainBidder);
bi.setItem(ai);
bi.setAmount(2.3F);
ai.getBids().add(bi);
List bids = new ArrayList();
bids.add(bi);
mainBidder.setBids(bids);
System.out.println("*********************BIDDER CHANGING****************");
test.changeUserDetails(mainBidder);
System.out.println("*********************BIDDER CHANGED****************");
test.factory.close();
and am getting:
........................................................
*********************BIDDER CHANGING****************
Changing user details for: 3
21:33:23,768 DEBUG SessionImpl:478 - opened session
21:33:23,768 DEBUG JDBCTransaction:36 - begin
21:33:23,768 DEBUG DriverManagerConnectionProvider:78 - total checked-out connections: 0
21:33:23,858 DEBUG DriverManagerConnectionProvider:84 - using pooled JDBC connection, pool size: 0
21:33:23,858 DEBUG Cascades:274 - unsaved-value strategy NULL
21:33:23,858 DEBUG SessionImpl:1296 - saveOrUpdate() previously saved instance with id: 3
21:33:23,868 DEBUG SessionImpl:1349 - updating [org.hibernate.auction.User#3]
21:33:23,959 DEBUG SessionImpl:1153 - collection dereferenced while transient [org.hibernate.auction.User.bids#3]
21:33:23,989 DEBUG SessionImpl:1153 - collection dereferenced while transient [org.hibernate.auction.User.auctions#3]
21:33:23,989 DEBUG Cascades:356 - processing cascades for: org.hibernate.auction.User
21:33:23,989 DEBUG Cascades:381 - cascading to collection: org.hibernate.auction.User.bids
21:33:24,069 DEBUG Cascades:105 - cascading to saveOrUpdate()
21:33:24,069 DEBUG Cascades:274 - unsaved-value strategy NULL
21:33:24,069 DEBUG SessionImpl:1291 - saveOrUpdate() unsaved instance
21:33:24,069 DEBUG SessionImpl:735 - saving [org.hibernate.auction.Bid#<null>]
21:33:24,069 DEBUG Cascades:274 - unsaved-value strategy NULL
21:33:24,089 DEBUG JDBCTransaction:73 - rollback
21:33:24,099 DEBUG SessionImpl:508 - transaction completion
21:33:24,099 DEBUG SessionImpl:496 - closing session
21:33:24,099 DEBUG SessionImpl:3283 - disconnecting session
21:33:24,099 DEBUG DriverManagerConnectionProvider:114 - returning connection to pool, pool size: 1
java.lang.NullPointerException: not-null property references a null or transient value: item
at net.sf.hibernate.impl.SessionImpl.nullifyTransientReferences(SessionImpl.java:900)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:803)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:682)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1292)21:33:24,099 DEBUG SessionImpl:508 - transaction completion
at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:106)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:296)
at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:404)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:312)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:361)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:341)
at net.sf.hibernate.impl.SessionImpl.doUpdate(SessionImpl.java:1384)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1297)
at org.hibernate.auction.Main.changeUserDetails(Main.java:159)
at org.hibernate.auction.Main.main(Main.java:393)
Exception in thread "main"
Am I doing smth wrong ??? TIA, Steve.
|