-->
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.  [ 3 posts ] 
Author Message
 Post subject: can any one gimme the various ways to insertions?
PostPosted: Tue Jun 14, 2005 12:52 pm 
Newbie

Joined: Thu May 05, 2005 10:22 am
Posts: 8
hi

i need to know the varous ways to insert a record in to DB without using save or saveupdate.

my criteria is like ... i need to insert a record without using save so that i need to autogenerate a coumn of my record 's column.
for that i need to use other ways to insert.
regular insert (save ) also works but i need to insert a record which is having a composite id inwhich one is increment and other one is assigned .
for that purpose only i need to insert thru other query types.
i tried with named query but its asking me return somethng for return ,but i m inserting in to DB,so i can't return anything ,its working but i m getting exceptioon.
so if my issue would solve thru other qury types like sql-query or query or createquery or createSQLquery.
i m trying to use sql-insert but its giving exceptions.
can anyone help me in this issue .as i need the solution very urgent....

(plz i need the code and mappings also,so that how can we call sql-insert in my mapping file and how to call at a certain time ....too)
Thanks in advance .......................


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 14, 2005 11:52 pm 
Beginner
Beginner

Joined: Mon Jun 13, 2005 5:52 pm
Posts: 43
My best guess would be to create a custom org.hibernate.id.IdentifierGenerator implementation and a custom org.hibernate.usertype.UserType to represent your key.

Keep in mind that you don't necessarily have to use the same primary key in Hibernate that you have in the database. As long as the sequence generated column serves as a valid key for the records (use a unique constraint), you may be able to use it instead. Be careful about how this might affect other related entites, though.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 17, 2005 1:18 am 
Newbie

Joined: Thu May 05, 2005 10:22 am
Posts: 8
thank you.....
i will try to do in this way!
but still ia have some doubts like how to implement the hashcode and the key?

for SQL time stamp i implemented a class for the same way..
but for sequence i m not able to get any idea .....

this is the class that i implemented for time stamp.......



package com.met.ib.ecomp.services.util;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;

import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;
import java.io.Serializable;


/**
* @author 119660
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class String2SqlTimestampFieldConversion implements UserType{

public String2SqlTimestampFieldConversion() {
super();
}

public int[] sqlTypes() {
return new int[] { Types.TIMESTAMP};
}

public Class returnedClass() {
return String.class;
}

public boolean equals(Object x, Object y) throws HibernateException {
return (x == y) || (x != null && y != null && (x.equals(y)));
}

public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
String val = rs.getTimestamp(names[0]).toString();
return val;

}

public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
System.out.println(value.getClass());
st.setTimestamp(index, Timestamp.valueOf((String)value));
}

public Object deepCopy(Object value) throws HibernateException {
return value;
}

public boolean isMutable() {
return false;
}
public Object replace(Object Ob1 ,Object Ob2,Object Ob3) throws HibernateException
{
return Ob2;
}
public Serializable disassemble(Object Ob1) throws HibernateException{
return (Serializable)Ob1;

}
public Object assemble(Serializable Ob1,Object Ob2){
return Ob2;
}
public int hashCode(Object Ob1) throws HibernateException{
return 0;

}
}


can anybody help me out in this issue...............


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