-->
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: Save data in Binary Field
PostPosted: Wed May 30, 2007 3:51 am 
Newbie

Joined: Mon May 28, 2007 2:25 am
Posts: 9
Hi all,

I am trying to save data on the binary field but when i am create the mapping file for the same it will create it as String...

My code is :

DataBase Field declaration is:

ColumnName DataType Length

hash1 binary 3

and my mapping file is :

public class Ttcmcs046550Id implements java.io.Serializable {


// Fields

private String TClan;
private String TDsca;
private String TLang;
private Integer TRefcntd;
private Integer TRefcntu;
private String hash1;


// Constructors

/** default constructor */
public Ttcmcs046550Id() {
}


/** full constructor */
public Ttcmcs046550Id(String TClan, String TDsca, String TLang, Integer TRefcntd, Integer TRefcntu, String hash1) {
this.TClan = TClan;
this.TDsca = TDsca;
this.TLang = TLang;
this.TRefcntd = TRefcntd;
this.TRefcntu = TRefcntu;
this.hash1 = hash1;
}


// Property accessors

public String getTClan() {
return this.TClan;
}

public void setTClan(String TClan) {
this.TClan = TClan;
}

public String getTDsca() {
return this.TDsca;
}

public void setTDsca(String TDsca) {
this.TDsca = TDsca;
}

public String getTLang() {
return this.TLang;
}

public void setTLang(String TLang) {
this.TLang = TLang;
}

public Integer getTRefcntd() {
return this.TRefcntd;
}

public void setTRefcntd(Integer TRefcntd) {
this.TRefcntd = TRefcntd;
}

public Integer getTRefcntu() {
return this.TRefcntu;
}

public void setTRefcntu(Integer TRefcntu) {
this.TRefcntu = TRefcntu;
}

public String getHash1() {
return this.hash1;
}

public void setHash1(String hash1) {
this.hash1 = hash1;
}

and save code is:

Session session = HibernateSessionFactory.getSession();
Transaction tx = null;
int TRefcntd=0;
int TRefcntu=0;
String s="te";


//begin the transaction.
tx = session.beginTransaction();

//Bussiness Logic
Ttcmcs045550Id ttcmcs = new Ttcmcs045550Id(areaCode,Description,TRefcntd,TRefcntu,s);
Ttcmcs045550 id = new Ttcmcs045550();
id.setId(ttcmcs);
session.save(id);
target="success";

it will give following error

org.hibernate.exception.GenericJDBCException: could not insert: [com.solversa.bean.Ttcmcs045550]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.BasicEntityPersister.insert(BasicEntityPersister.java:1788)
at org.hibernate.persister.BasicEntityPersister.insert(BasicEntityPersister.java:2120)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:48)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:271)
at org.hibernate.event.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:24)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:719)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:84)
at com.solversa.masters.service.MaintainAreaServiceImpl.addMaintainArea(MaintainAreaServiceImpl.java:54)
at com.solversa.masters.actions.AddMaintainArea.execute(AddMaintainArea.java:39)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Disallowed implicit conversion from data type nvarchar to data type binary, table 'mfgappl.dbo.ttcmcs045550', column 'hash1'. Use the CONVERT function to run this query.
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.BasicEntityPersister.insert(BasicEntityPersister.java:1772)
... 31 more
pls help me

Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 4:11 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

change it to Binary data type


Amila

(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject: Hi
PostPosted: Wed May 30, 2007 4:15 am 
Newbie

Joined: Mon May 28, 2007 2:25 am
Posts: 9
Where i need to change...

Pls give some details Explanation...

Thanks
amila733 wrote:
Hi

change it to Binary data type


Amila

(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 4:32 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

Code:
private String hash1;


change datataype String to Binary or Serializable

Amila
(Don't forget to rate if helps)


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.