-->
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.  [ 4 posts ] 
Author Message
 Post subject: one-one mapping child table record not inserting
PostPosted: Thu Feb 19, 2009 4:09 pm 
Newbie

Joined: Thu Feb 19, 2009 4:04 pm
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

[b]Hibernate version:3.0[/b]

[b]Mapping documents:

-- Ticket Master Entity--

@Entity
@Table(name="Ticket_Master")
public class TicketMaster {
// @Id
// @GeneratedValue
// @Column(name="ID")
// private Long id;

@Id
@Column(name="TICKET_ID")
private String ticketID;

@Column(name="ASSGN_USER_ID")
private String assgnUserID;
@Column(name="ASSGN_GROUP_ID")
private Long assgnGroupID;
@Column(name="ASSGN_DEPT_ID")
private Long assgnDeptID;
@Column(name="BRANCH_ID")
private Long assgnBranchID;
@Column(name="TICKET_CREATED_BY")
private String ticketCreatedBy;
@Column(name="TICKET_STATUS_ID")
private Long ticketStatusID;
@Column(name="TICKET_PRIORITY_ID")
private Long ticketPriorityID;
@Column(name="TERM_TYPE_ID")
private Long termTypeID;
@Column(name="CREATED_BY")
private Long createdBy;
@Column(name="CREATE_DATE")
private Date createdDate;
@Column(name="LAST_UPDATE_BY")
private Long lastUpdateBy;
@Column(name="LAST_UPDATE_DATE")
private Date lastUpdateDate;

@OneToOne(mappedBy="ticketMaster")
@PrimaryKeyJoinColumn
private AirRegister airRegister;


public AirRegister getAirRegister() {
return airRegister;
}
public void setAirRegister(AirRegister airRegister) {
this.airRegister = airRegister;
}

@OneToOne(mappedBy="ticketMaster")
@PrimaryKeyJoinColumn
private SeaRegister seaRegister;


public SeaRegister getSeaRegister() {
return seaRegister;
}
public void setSeaRegister(SeaRegister seaRegister) {
this.seaRegister = seaRegister;
}

-- TicketMaster Entity --

-- AirRegister Entity --

@Id
@GeneratedValue
@Column(name="ID")
private Long id;
@OneToOne
@JoinColumn(name="TICKET_AIR_REG_ID")
private TicketMaster ticketMaster;
@Column(name="DEPT_AIRPORT")
private String deptAirport;
@Column(name="DEST_AIRPORT")
private String destAirport;
@Column(name="AIRLINE_TYPE")
private String airlineType;
@Column(name="FLIGHT_NR")
private String flightNR;
@Column(name="GOODS_WEIGHT")
private String goodsWeight;
@Column(name="CREATED_BY")
private Long createdBy;
@Column(name="CREATE_DATE")
private Date createdDate;
@Column(name="LAST_UPDATE_BY")
private Long lastUpdateBy;
@Column(name="LAST_UPDATE_DATE")
private Date lastUpdateDate;
-- AirRegister Entity
[/b]

[b]

Session session = sessionFactory.openSession();
System.out.println(session);
Transaction tx = session.getTransaction();
System.out.println("Tx get");
try {
System.out.println("Tx before begin");
tx.begin();
System.out.println("Tx After begin");
session.saveOrUpdate(ticketMaster);

tx.commit();
} catch (RuntimeException e) {
tx.rollback();
throw e;
} finally {
session.close();
}

b]

[b]No exception is coming; record inserted into master table; child tables not inserting[/b]

[b]Name and version of the database you are using:[/b]

[b]The generated SQL (show_sql=true):[/b]

[b]Debug level Hibernate log excerpt:[/b]


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2009 8:14 pm 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
Did you try setting the cascade attribute on the one to one?


Top
 Profile  
 
 Post subject: one-one mapping child table record not inserting
PostPosted: Fri Feb 20, 2009 11:02 am 
Newbie

Joined: Thu Feb 19, 2009 4:04 pm
Posts: 2
yes its working:

-- Ticket Master --

@OneToOne(mappedBy="ticketMaster" ,cascade = CascadeType.ALL)
@PrimaryKeyJoinColumn
private AirRegister airRegister;


public AirRegister getAirRegister() {
return airRegister;
}
public void setAirRegister(AirRegister airRegister) {
this.airRegister = airRegister;
}

--Ticket Master --

-- Air Register --

@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="TICKET_AIR_REG_ID")
private TicketMaster ticketMaster;

-- Air Register--


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2009 12:33 pm 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
Glad I could help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.