Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » mapping custom types
mapping custom types [message #636011] Thu, 28 October 2010 22:52 Go to next message
anil chalil is currently offline anil chalilFriend
Messages: 38
Registered: October 2010
Member
Hello,

I created a type in Oracle 11g here is the code:
CREATE OR REPLACE TYPE XILM.cm_info_t

AS OBJECT

(

created_by VARCHAR2 (30) ,

create_time DATE ,

last_modification_time DATE ,

last_modified_by VARCHAR2 (30)

) NOT FINAL

;

I want to map this type in my project. I created a class InfoConverter
public class InfoConverter implements StructConverter {

private static final String CM_INFO_T = "xilm.cm_info_t";

private static final Logger LOGGER = LoggerFactory
.getLogger(InfoConverter.class);

@Override
public Object convertToObject(Struct mystruct) throws SQLException {
LOGGER.debug("convert called");
Object cols[] = mystruct.getAttributes();
Info info = new Info();
info.setCreatedBy((String) cols[0]);
info.setCreationTime((Date) cols[1]);
info.setModificationTime((Date) cols[2]);
info.setLastModifiedBy((String) cols[3]);
return info;
}

@Override
public Struct convertToStruct(Object arg0, Connection arg1)
throws SQLException {
StructDescriptor colStructDesc = StructDescriptor.createDescriptor(
CM_INFO_T, arg1);
Info info = (Info) arg0;
Object[] objectArray = new Object[4];
objectArray[0] = info.getCreatedBy();
objectArray[1] = info.getCreationTime();
objectArray[2] = info.getModificationTime();
objectArray[3] = info.getLastModifiedBy();
oracle.sql.STRUCT colStruct = new STRUCT(colStructDesc, arg1,
objectArray);
return colStruct;
}

@Override
public Class<Info> getJavaType() {
return Info.class;
}

@Override
public String getStructName() {
return CM_INFO_T;
}

}

My current mapping which uses this type is like

@Entity
@Table(name = "ILM_WORKSPACE")
@StructConverter(name = "infoConverter", converter = "com.globalmaksimum.dao.workspace.jpa.InfoConverter")
public class Workspace implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SQ_WORKSPACE")
@Column(name = "WORKSPACE#")
@SequenceGenerator(name = "SQ_WORKSPACE", sequenceName = "SQ_WORKSPACE", allocationSize = 1)
private long workspace_;

@Convert("infoConverter")
@Column(name = "CM_INFO")
private Info cmInfo;

private BigDecimal status;

@Column(name = "WORKSPACE_DESC")
private String workspaceDesc;

@Column(name = "WORKSPACE_DOP")
private BigDecimal workspaceDop;

@Column(name = "WORKSPACE_NAME")
private String workspaceName;

// bi-directional many-to-one association to ExecutionInfo
@ManyToOne
@JoinColumn(name = "SCHEDULE#")
private ExecutionInfo ilmSchedule;

// bi-directional many-to-one association to Task
@OneToMany(mappedBy = "ilmWorkspace")
private Set<Task> ilmWorkspaceTasks;

public Workspace() {
}

public long getWorkspace_() {
return this.workspace_;
}

public void setWorkspace_(long workspace_) {
this.workspace_ = workspace_;
}

public Info getCmInfo() {
return this.cmInfo;
}

public void setCmInfo(Info cmInfo) {
this.cmInfo = cmInfo;
}

public BigDecimal getStatus() {
return this.status;
}

public void setStatus(BigDecimal status) {
this.status = status;
}

public String getWorkspaceDesc() {
return this.workspaceDesc;
}

public void setWorkspaceDesc(String workspaceDesc) {
this.workspaceDesc = workspaceDesc;
}

public BigDecimal getWorkspaceDop() {
return this.workspaceDop;
}

public void setWorkspaceDop(BigDecimal workspaceDop) {
this.workspaceDop = workspaceDop;
}

public String getWorkspaceName() {
return this.workspaceName;
}

public void setWorkspaceName(String workspaceName) {
this.workspaceName = workspaceName;
}

public ExecutionInfo getIlmSchedule() {
return this.ilmSchedule;
}

public void setIlmSchedule(ExecutionInfo ilmSchedule) {
this.ilmSchedule = ilmSchedule;
}

public Set<Task> getIlmWorkspaceTasks() {
return this.ilmWorkspaceTasks;
}

public void setIlmWorkspaceTasks(Set<Task> ilmWorkspaceTasks) {
this.ilmWorkspaceTasks = ilmWorkspaceTasks;
}

}

Project is a JPA project which uses spring and eclipselink as JPA provider. But in tests it throws an exception when trying to map Workspace entity here is the stack trace

------------------------------------------------------------ -------------------
Test set: org.workspacedao.DaoTest
------------------------------------------------------------ -------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 20.861 sec <<< FAILURE!
testGetExecutionInfo(org.workspacedao.DaoTest) Time elapsed: 20.521 sec <<< ERROR!
Local Exception Stack:
Exception [EclipseLink-3002] (Eclipse Persistence Services - 2.1.1.v20100817-r8050): org.eclipse.persistence.exceptions.ConversionException
Exception Description: The object [[Ljava.lang.Object;@699c9f16], of class [class [Ljava.lang.Object;], from mapping [org.eclipse.persistence.mappings.DirectToFieldMapping[cmInf o-- >ILM_WORKSPACE.CM_INFO]] with descriptor [RelationalDescriptor(com.globalmaksimum.dao.workspace.jpa.W orkspace --> [DatabaseTable(ILM_WORKSPACE)])], could not be converted to [class com.globalmaksimum.dao.workspace.jpa.Info].
at org.eclipse.persistence.exceptions.ConversionException.could NotBeConverted(ConversionException.java:71)
at org.eclipse.persistence.internal.helper.ConversionManager.co nvertObject(ConversionManager.java:169)
at org.eclipse.persistence.internal.databaseaccess.DatasourcePl atform.convertObject(DatasourcePlatform.java:157)
at org.eclipse.persistence.platform.database.oracle.Oracle9Plat form.convertObject(Oracle9Platform.java:358)
at org.eclipse.persistence.mappings.foundation.AbstractDirectMa pping.getAttributeValue(AbstractDirectMapping.java:680)
at org.eclipse.persistence.mappings.foundation.AbstractDirectMa pping.valueFromRow(AbstractDirectMapping.java:1263)
at org.eclipse.persistence.mappings.DatabaseMapping.readFromRow IntoObject(DatabaseMapping.java:1283)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildAttributesIntoObject(ObjectBuilder.java:342)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildObject(ObjectBuilder.java:711)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildObject(ObjectBuilder.java:504)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildObjectsInto(ObjectBuilder.java:904)
at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLe velReadQuery(ReadAllQuery.java:423)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute DatabaseQuery(ObjectLevelReadQuery.java:1074)
at org.eclipse.persistence.queries.DatabaseQuery.execute(Databa seQuery.java:736)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute (ObjectLevelReadQuery.java:1034)
at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAll Query.java:380)
at org.eclipse.persistence.internal.sessions.AbstractSession.in ternalExecuteQuery(AbstractSession.java:2392)
at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1291)
at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1273)
at org.eclipse.persistence.internal.indirection.QueryBasedValue Holder.instantiate(QueryBasedValueHolder.java:85)
at org.eclipse.persistence.internal.indirection.QueryBasedValue Holder.instantiate(QueryBasedValueHolder.java:75)
at org.eclipse.persistence.internal.indirection.DatabaseValueHo lder.getValue(DatabaseValueHolder.java:83)
at org.eclipse.persistence.internal.indirection.UnitOfWorkValue Holder.instantiateImpl(UnitOfWorkValueHolder.java:160)
at org.eclipse.persistence.internal.indirection.UnitOfWorkValue Holder.instantiate(UnitOfWorkValueHolder.java:220)
at org.eclipse.persistence.internal.indirection.DatabaseValueHo lder.getValue(DatabaseValueHolder.java:83)
at org.eclipse.persistence.indirection.IndirectSet.buildDelegat e(IndirectSet.java:192)
at org.eclipse.persistence.indirection.IndirectSet.getDelegate( IndirectSet.java:343)
at org.eclipse.persistence.indirection.IndirectSet.size(Indirec tSet.java:500)
at org.workspacedao.DaoTest.testGetExecutionInfo(DaoTest.java:3 3)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBefore TestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.ja va:74)
at org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
at org.springframework.test.context.junit4.statements.RunAfterT estMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java :82)
at org.springframework.test.context.junit4.statements.SpringRep eat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRun ner.runChild(SpringJUnit4ClassRunner.java:240)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
at org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBefore TestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java :61)
at org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
at org.springframework.test.context.junit4.statements.RunAfterT estClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:7 0)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.springframework.test.context.junit4.SpringJUnit4ClassRun ner.run(SpringJUnit4ClassRunner.java:180)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit 4TestSet.java:59)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.e xecuteTestSet(AbstractDirectoryTestSuite.java:115)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.e xecute(AbstractDirectoryTestSuite.java:102)
at org.apache.maven.surefire.Surefire.run(Surefire.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInP rocess(SurefireBooter.java:350)
at org.apache.maven.surefire.booter.SurefireBooter.main(Surefir eBooter.java:1021)

I dont understand where i is the mistake?

[Updated on: Thu, 28 October 2010 22:52]

Report message to a moderator

Re: mapping custom types [message #636174 is a reply to message #636011] Fri, 29 October 2010 14:26 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello,

The struct name might be wrong, as I believe you have it defined in the value returned by getStructName "xilm.cm_info_t" in lower case while the database will be returning it as "XILM.CM_INFO_T". The lower case string is fine when building a struct as the database is case sensitive, but looking up the converter using the upper case string returned from the database when it is hashed on the getStructName will only work if the case matches exactly.

Best Regards,
Chris
Re: mapping custom types [message #636188 is a reply to message #636174] Fri, 29 October 2010 15:11 Go to previous message
anil chalil is currently offline anil chalilFriend
Messages: 38
Registered: October 2010
Member
Oh thanks a lot chris. I have struggled with the issue for two days:)
Previous Topic:connecting an application to two different JNDI datasources
Next Topic:Validation errors for Eclipselink 2.1.1 project.xml
Goto Forum:
  


Current Time: Fri Apr 26 02:55:53 GMT 2024

Powered by FUDForum. Page generated in 0.03320 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top