Showing posts with label hibernate. Show all posts
Showing posts with label hibernate. Show all posts

8/12/2010

How to call database store procedure with return parameter from EJB3


@Resource(mappedName = "java:/myDatasource")
private DataSource ds;

public void callSetLoginUserId(String userId) throws Exception {
Connection conn = null;
CallableStatement st = null;
try {
String sql = "{ ? = call my_pkg.create_user(?) }";
conn = ds.getConnection();
st = conn.prepareCall(sql);
st.registerOutParameter(1, Types.BIGINT);
st.setString(2, "username");
st.execute();
Long userId = st.getLong(1);
}
catch(Exception e) {
log.error("calling my_pkg.create_user has failed", e);
throw e;
}
finally {
try {
if (st != null) {
st.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
// ignore
}
}

9/05/2008

hibernate: many-to-many mapping with mapping-table

<set name="items" table="campaignlist" >
<key column="campaign_id"/>
<many-to-many class="Item" column="mediaitem_id"/>
</set>

OR

<bag name="otherOptions" table="JOB_FINISHING_OPTION">
<key column="JOB_ID"/>
<many-to-many class="com.au.fxa.dsc.soms.model.PrintFinishOption" column="POC_ID"/>
</bag>