Hibernate Insert Failing...

M

Mongoose

Hi All,

I'm a beginner with Hibernate and I'm having trouble understanding how
to insert dates into an Oracle database properly. In my Struts
application I have my Defect Class (a portion of which is shown
below). The relevant portion of my Hibernate Defect.hbm.xml is also
shown below. When I fill out my .jsp and submit it . . . I get this
error:

"java.lang.IllegalArgumentException: Cannot
invoke ....Defect.setReportdatetime - argument type mismatch"

I don't understand how to do this. Can someone straighten me out?

Thanks,

Andy


********** Relevant part of Form Bean **************************


public class Defect extends ActionForm
{
//Form Bean For the Defect Entry Screen

private Date reportdatetime;


public Date getReportdatetime()
{
return reportdatetime;
}

public void setReportdatetime(Date reportdatetime)
{
this.reportdatetime = reportdatetime;
}


********** Relevant part of Defect.hbm.xml **************************

<class name="Defect" table="Defect">
<id name="Defectid" type="integer" column="DEFECTID">
<generator class="native"/>
</id>
<property name="Reportdatetime"/>
<property name="Reporteruserid"/>
 
L

Lew

Mongoose said:
<class name="Defect" table="Defect">
        <id name="Defectid" type="integer" column="DEFECTID">
                <generator class="native"/>
        </id>
        <property name="Reportdatetime"/>
        <property name="Reporteruserid"/>

Specify the Hibernate types in the XML, and use a lower-case first
letter for property names and camel case within names...

<property name="reportTime" type="timestamp" column="reportTime" />
<property name="uiserId" type="string" column="userId" />
 
M

Mongoose

Specify the Hibernate types in the XML, and use a lower-case first
letter for property names and camel case within names...

  <property name="reportTime" type="timestamp" column="reportTime" />
  <property name="uiserId" type="string" column="userId" />

Hey Lew,

I added all the types to the .xml file as shown below:

<class name="Defect" table="Defect">
<id name="Defectid" type="integer" column="DEFECTID">
<generator class="native"/>
</id>
<property name="description" type="string"/>
<property name="priorityid" type="integer"/>
<property name="reportdatetime" type="date"/>
<property name="reporteruserid" type="integer"/>
<property name="functionalareaid" type="integer"/>
<property name="statusid" type="integer"/>
<property name="severity" type="string"/>
<property name="teamleadid" type="integer"/>
<property name="detectiondatetime" type="date"/>
<property name="estfixtime" type="integer"/>
<property name="actfixtime" type="integer"/>
<property name="statusdate" type="date"/>
<property name="assignedtouserid" type="integer"/>
<property name="assignedtodate" type="date"/>
<property name="fixedbyuserid" type="integer"/>
</class>

However, I don't think the case is the root cause of the problem
because when I change the ReportDateTime from a Date to a String in
the Defect Class it works fine with the current case . . . .

A
 
C

ck

However, I don't think the case is the root cause of the problem
because when I change the ReportDateTime from a Date to a String in
the Defect Class it works fine with the current case . . . .

As suggested by Lew, did you try using "timestamp"?
 
M

Mongoose

As suggested by Lew, did you try using "timestamp"?

Lew/Ck,

I tried to change all "date" types to "timestamp" types in the
hibernate .xml file but get the same error . . .

I need more information to solve this problem. Is there some logging
mechanism that might provide more info . . .

A
 
L

Lew

Lew/Ck,

I tried to change all "date" types to "timestamp" types in the
hibernate .xml file but get the same error . . .

Prepare us an SSCCE:
<http://sscce.org/>
that illustrates your problem. That means we need *complete* (but
simplified) Java code, DDL and mapping XML. As it stands your XML
shows all kinds of columns for which you don't show DDL or Java code,
your spelling violates the naming conventions, and you don't even tell
us what the type of attribute 'reportdatetime' [sic] is.

You don't just declare a field map to Hibernate type 'timestamp' willy-
nilly; you have to match the Java-side and Hibernate-side types, thus
'java.sql.Timestamp' maps to Hibernate 'Timestamp', but
'java.util.Date' does not, necessarily. You have to check the
Hibernate documentation for the exact correspondences; I don't
remember them all off the top of my head. It's something like
java.sql.Date -> date
java.sql.Time -> time
java.sql.Timestamp -> timestamp
etc.

Remember, to get good help you need to provide an SSCCE.
 
M

Mongoose

Lew/Ck,

I tried to change all "date" types to "timestamp" types in the
hibernate .xml file but get the same error . . .

I need more information to solve this problem.  Is there some logging
mechanism that might provide more info . . .

A

Ok, I think I was wrong about the "case issue" so I changed the
mapping file, bean, and .jsp to camel case (thanks Lew!) Now,
everything works fine except when I try to insert my dates. Now, what
I have is shown below. The property in question is: "reportDt".
When I try to do a Hibernate Insert for "reportDt" . . . I get
"Argument Type Mismatch".

A


/*** Portion of Main Bean **/

public class Defect extends ActionForm
{
//Form Bean For the Defect Entry Screen

private Integer defectId;
private String description;
private Integer priorityId;

private Date reportDt;
private Integer reporterUserId;
private Integer functionalAreaId;
private Integer statusId;
private String severity;
private Integer teamLeadId;
private Date detectionDateTime;
private Integer estFixTime;
private Integer actFixTime;
private Date statusDate;
private Integer assignedToUserId;
private Date assignedToDate;
private Integer fixedByUserId;


public Date getReportDt() {
return reportDt;
}


public void setReportDt(Date reportDt) {
this.reportDt = reportDt;
}

/******** End Portion of Main Bean *************/

/************ Portion of Hibernate Mapping .xml ************/

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="gov.ohio.odjfs.struts">

<class name="Defect" table="Defect">
<id name="defectId" type="integer" column="DEFECTID">
<generator class="native"/>
</id>
<property name="description" type="string"/>
<property name="priorityId" type="integer"/>
<property name="reportDt" type="timestamp" column="REPORTDATETIME"/>
<property name="reporterUserId" type="integer"/>

/*********** End portion of hibernate mapping .xml
*********************/

/*********** Portion of data entry form .jsp ********************/

html:html>
<head>
<title>adddefect</title>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<link rel="stylesheet" href="styles/form.css" type="text/css">
</head>
<body>
<html:form action="adddefect" method="post">

<table class="tableinputform" >
<tr>
<th>Description</th>
<td><html:text property="description"/></td>
</tr>
<tr>
<th>PriorityID</th>
<td><html:text property="priorityId"/></td>
</tr>

<tr>
<th>ReportDateTime</th>
<td><html:text property="reportDt"/></td>
</tr>

/********** End portion of data entry form .jsp ***************/
 
L

Lew

Mongoose said:
Ok, I think I was wrong about the "case issue" so I changed the
mapping file, bean, and .jsp to camel case (thanks Lew!) Now,
everything works fine except when I try to insert my dates. Now, what
I have is shown below. The property in question is: "reportDt".
When I try to do a Hibernate Insert for "reportDt" . . . I get
"Argument Type Mismatch".
...
private Date reportDt;
...
<property name="reportDt" type="timestamp" column="REPORTDATETIME"/>

Side note: do not embed TAB characters in Usenet posts. Use a maximum of four
spaces for each tab level instead.

My previous post discusses reading the Hibernate documentation to ensure a
match between the Hibernate type and the Java type.

You haven't told us the Java type of 'reportDt' yet. The rule of thumb is
'java.sql.Date' for dates with day resolution (no times), 'java.sql.Time' for
times without date information, and 'java.sql.Timestamp' to match SQL
TIMESTAMP columns, that is, to hold date/time information.

Carefully study <http://sscce.org/> for how to present a Usenet example.
 
M

Mongoose

Side note: do not embed TAB characters in Usenet posts.  Use a maximum of four
spaces for each tab level instead.

My previous post discusses reading the Hibernate documentation to ensure a
match between the Hibernate type and the Java type.

You haven't told us the Java type of 'reportDt' yet.  The rule of thumb is
'java.sql.Date' for dates with day resolution (no times), 'java.sql.Time' for
times without date information, and 'java.sql.Timestamp' to match SQL
TIMESTAMP columns, that is, to hold date/time information.

Carefully study <http://sscce.org/> for how to present a Usenet example.

Hey Lew,

I've solved this problem using the following types:

DATE in Oracle 10g
DATE in Hibernate Map
java.sql.date in Java Application

Thanks for your help . . . everything is working properly now . . .

Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top