After stepping into the MappingTool code path, I found the problem lies in
the following module.
The problem is the when cols is empty, this method create a new cols List
but the new cols is NOT being set back to the fm.getValueInfo()._cols field.
I experimented by adding the setColumn() with the new List and now the
example is generating:
C:\a.workspace\eclipse.workspace\wasx.jpa.jse.test\JPA.JSE>type create.sql
CREATE TABLE JSEEmployee (id INTEGER NOT NULL, date DATE, name VARCHAR(254),
salary BIGINT, PRIMARY KEY (id));
Can someone with more experience and insight in this module and validate if
this is the correct action to fix the problem?
Thanks
Albert Lee.
--------------------------------------------------------------
AnnotationPersistenceMappingParser.java
/**
* Parse @Temporal.
*/
private void parseTemporal(FieldMapping fm, Temporal anno) {
List cols = fm.getValueInfo().getColumns();
if (!cols.isEmpty() && cols.size() != 1)
throw new MetaDataException(_loc.get("num-cols-mismatch", fm,
String.valueOf(cols.size()), "1"));
if (cols.isEmpty()) {
cols = Arrays.asList(new Column[]{ new Column() });
fm.getValueInfo().setColumns(cols); // <<<<<<<< add this line
to use the new cols List.
}
Column col = (Column) cols.get(0);
switch (anno.value()) {
case DATE:
col.setType(Types.DATE);
break;
case TIME:
col.setType(Types.TIME);
break;
case TIMESTAMP:
col.setType(Types.TIMESTAMP);
break;
}
}
On 7/29/07, Albert Lee <[EMAIL PROTECTED]> wrote:
>
> I have a simple entity:
>
> @Entity
> @Table(name = "JSEEmployee")
> public class Employee {
> @Id
> private int id;
> ......
> @Temporal(TemporalType.DATE)
> private java.util.Date date;
> .....
> }
>
> When I run the mapping tool to generated the sql as in below, the "date"
> column is still a TIMESTAMP type. Would it be of DATE type due to the
> @Temporal annotation ?
>
> ------------------------------------------------
> C:\a.workspace\eclipse.workspace\wasx.jpa.jse.test\JPA.JSE>java
> org.apache.openjpa.jdbc.meta.MappingTool -sa build -sql create.sql
> 16 Employee TRACE [main] openjpa.Runtime - Setting the following
> properties from
> "file:/C:/a.workspace/eclipse.workspace/wasx.jpa.jse.test/JPA.JSE/META-INF/persistence.xml"
> into configuration: { openjpa.ConnectionURL=jdbc:db2:WSTest,
> openjpa.Id=Employee, openjpa.ConnectionUserName=leealber,
> openjpa.Log=DefaultLevel=TRACE, MetaData=TRACE, Runtime=TRACE,
> Enhance=TRACE, SQL=TRACE, openjpa.jdbc.DBDictionary=db2,
> openjpa.MetaDataFactory=jpa (Types=suite.r70.jse.Employee),
> javax.persistence.provider=com.ibm.websphere.persistence.PersistenceProviderImpl,
> openjpa.ConnectionDriverName=COM.ibm.db2.jdbc.app.DB2Driver,
> openjpa.ConnectionPassword=fth616dy,
> openjpa.jdbc.SynchronizeMappings=buildSchema }
> 63 Employee INFO [main] openjpa.jdbc.JDBC - Using dictionary class "
> org.apache.openjpa.jdbc.sql.DB2Dictionary".
> 78 Employee INFO [main] openjpa.Tool - No targets were given. Running
> on all classes listed in your configuration,or all persistent classes in the
> classpath if no classes are configured. Use -help to display tool usage
> information.
> 125 Employee TRACE [main] openjpa.MetaData - Using metadata factory "
> [EMAIL PROTECTED]".
> 125 Employee TRACE [main] openjpa.MetaData - Scanning resource
> "META-INF/orm.xml" for persistent types.
> 141 Employee TRACE [main] openjpa.MetaData - parsePersistentTypeNames()
> found [suite.r70.jse.Employee].
> 141 Employee TRACE [main] openjpa.MetaData - Found 1 classes with
> metadata in 16 milliseconds.
> 141 Employee INFO [main] openjpa.Tool - Mapping tool running on type
> "class suite.r70.jse.Employee" with action "buildSchema".
> 141 Employee TRACE [main] openjpa.MetaData - Using metadata factory "
> [EMAIL PROTECTED] ".
> 141 Employee TRACE [main] openjpa.MetaData - Loading metadata for
> "class suite.r70.jse.Employee" under mode "[META][QUERY]".
> 141 Employee TRACE [main] openjpa.MetaData - Scanning resource
> "META-INF/orm.xml" for persistent types.
> 141 Employee TRACE [main] openjpa.MetaData - parsePersistentTypeNames()
> found [suite.r70.jse.Employee].
> 141 Employee TRACE [main] openjpa.MetaData - Found 1 classes with
> metadata in 0 milliseconds.
> 172 Employee TRACE [main] openjpa.MetaData - Parsing class "
> suite.r70.jse.Employee".
> 172 Employee TRACE [main] openjpa.MetaData - Parsing package "
> suite.r70.jse.Employee".
> 203 Employee TRACE [main] openjpa.MetaData - Generating default
> metadata for type " suite.r70.jse.Employee".
> 234 Employee TRACE [main] openjpa.MetaData - Set persistence-capable
> superclass of "suite.r70.jse.Employee" to "null".
> 234 Employee TRACE [main] openjpa.MetaData - Resolving metadata for "
> [EMAIL PROTECTED]".
> 234 Employee TRACE [main] openjpa.MetaData - Resolving field
> "[EMAIL PROTECTED]
> ".
> 250 Employee TRACE [main] openjpa.MetaData - Resolving field "
> [EMAIL PROTECTED]".
> 250 Employee TRACE [main] openjpa.MetaData - Resolving field "
> [EMAIL PROTECTED]".
> 250 Employee TRACE [main] openjpa.MetaData - Resolving field "
> [EMAIL PROTECTED]".
> 250 Employee TRACE [main] openjpa.MetaData - Preparing mapping for "
> suite.r70.jse.Employee".
> 250 Employee TRACE [main] openjpa.MetaData - Resolving field "
> [EMAIL PROTECTED]".
> 266 Employee TRACE [main] openjpa.MetaData - "id" has mapping
> strategy "org.apache.openjpa.jdbc.meta.strats.PrimitiveFieldStrategy".
> 266 Employee TRACE [main] openjpa.MetaData - Resolving field
> "[EMAIL PROTECTED]
> ".
> 266 Employee TRACE [main] openjpa.MetaData - "date" has mapping
> strategy "org.apache.openjpa.jdbc.meta.strats.HandlerFieldStrategy".
> 266 Employee TRACE [main] openjpa.MetaData - Resolving field "
> [EMAIL PROTECTED]".
> 266 Employee TRACE [main] openjpa.MetaData - "name" has mapping
> strategy " org.apache.openjpa.jdbc.meta.strats.StringFieldStrategy".
> 266 Employee TRACE [main] openjpa.MetaData - Resolving field
> "[EMAIL PROTECTED]
> ".
> 266 Employee TRACE [main] openjpa.MetaData - "salary" has
> mapping strategy "
> org.apache.openjpa.jdbc.meta.strats.PrimitiveFieldStrategy".
> 266 Employee TRACE [main] openjpa.MetaData -
> "suite.r70.jse.Employee<discriminator>"
> has mapping strategy "none".
> 266 Employee TRACE [main] openjpa.MetaData -
> "suite.r70.jse.Employee<version>"
> has mapping strategy "none".
> 266 Employee TRACE [main] openjpa.MetaData - Resolving mapping for "
> [EMAIL PROTECTED]".
> 266 Employee TRACE [main] openjpa.MetaData - "suite.r70.jse.Employee"
> has mapping strategy "full".
> 266 Employee INFO [main] openjpa.Tool - Recording mapping and schema
> changes.
> 391 Employee TRACE [main] openjpa.MetaData - Clearing metadata
> repository "[EMAIL PROTECTED] ".
>
> C:\a.workspace\eclipse.workspace\wasx.jpa.jse.test\JPA.JSE>type create.sql
> CREATE TABLE JSEEmployee (id INTEGER NOT NULL, date TIMESTAMP, name
> VARCHAR(254), salary BIGINT, PRIMARY KEY (id));
> ------------------------------------------------
> 8.1.3. Temporal Types
>
> The Temporal annotation determines how the implementation handles your
> basic java.util.Date and java.util.Calendar fields at the JDBC level. The
> Temporal annotation's value is a constant from the TemporalType enum.
> Available values are:
>
> -
>
> TemporalType.TIMESTAMP: The default. Use JDBC's timestamp APIs to
> manipulate the column data.
> -
>
> TemporalType.DATE: Use JDBC's SQL date APIs to manipulate the column
> data.
> -
>
> TemporalType.TIME: Use JDBC's time APIs to manipulate the column
> data.
>
> If the Temporal annotation is omitted, the implementation will treat the
> data as a timestamp.
>
> The corresponding XML element is temporal, whose text value must be one
> of: TIME, DATE, or TIMESTAMP.
>
> Albert Lee.
>