| orm.xml - customizing table name [message #740421] |
Tue, 18 October 2011 09:49  |
Mauro Flores Messages: 83 Registered: September 2009 Location: Brasil |
Member |
|
|
How do I write an orm.xml file to customize only the name of the database table mapped to an entity?
Any other mapping I want to configure using annottation.
Does anybody has an example?
Thanks. Mauro.
|
|
|
|
|
| Re: orm.xml - customizing table name [message #740675 is a reply to message #740493] |
Tue, 18 October 2011 15:21   |
Mauro Flores Messages: 83 Registered: September 2009 Location: Brasil |
Member |
|
|
Thanks, Chris. It almost worked.
Unfortunally two annottations were ignored:
1) @Temporal
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "DATA_HORA")
private Calendar dataHora;
Exception Description: The attribute [dataHora] from the entity class [class X] does not specify a temporal type. A temporal type must be specified for persistent fields or properties of type java.util.Date and java.util.Calendar.
at org.eclipse.persistence.exceptions.ValidationException.noTemporalTypeSpecified(ValidationException.java:1375)
2) @Id
@Id
@Column(name = "NRO_INT_AUDITORIA")
private Long nroIntAuditoria;
Exception Description: Entity class [class X] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass. If you have defined PK using any of these annotations then make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
I will try now to define this two information redundantly in orm.xml:
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
version="1.0">
<entity name="EntityName" class="X"
access="PROPERTY">
<table name="TABLE" />
<attributes>
<id name="nroIntAuditoria"></id>
<basic name="dataHora"><temporal>TIMESTAMP</temporal></basic>
</attributes>
</entity>
</entity-mappings>
[Updated on: Tue, 18 October 2011 15:22] Report message to a moderator
|
|
|
| Re: orm.xml - customizing table name [message #740684 is a reply to message #740675] |
Tue, 18 October 2011 15:35  |
Mauro Flores Messages: 83 Registered: September 2009 Location: Brasil |
Member |
|
|
My mistake, Chris! Ignore my last post.
Your solution worked.
In my first try I was using access="PROPERTY" and I should use "FIELD".
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
version="1.0">
<entity name="AuditoriaED" class="X"
access="FIELD">
<table name="TABLE" />
</entity>
</entity-mappings>
Thanks.
|
|
|
|
Powered by
FUDForum. Page generated in 0.10114 seconds