Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » orm.xml - customizing table name
orm.xml - customizing table name [message #740421] Tue, 18 October 2011 13:49 Go to next message
Mauro Flores is currently offline Mauro FloresFriend
Messages: 84
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 #740491 is a reply to message #740421] Tue, 18 October 2011 15:10 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1039
Registered: July 2009
Senior Member
Hello,

The orm.xml file is merged overtop of the annotations, so you only need to define what you need to have changed. A simple orm.xml might look like:

<entity-mappings version="2.0" 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 orm_2_0.xsd">
    <entity name="EntityName" class="package.Entity" access="PROPERTY">
        <table name="TABLE_NAME"/>
    </entity>
...
</entity-mappings>


Best Regards,
Chris
Re: orm.xml - customizing table name [message #740493 is a reply to message #740421] Tue, 18 October 2011 15:10 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1039
Registered: July 2009
Senior Member
Hello,

The orm.xml file is merged overtop of the annotations, so you only need to define what you need to have changed. A simple orm.xml might look like:

<entity-mappings version="2.0" 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 orm_2_0.xsd">
<entity name="EntityName" class="package.Entity" access="PROPERTY">
<table name="TABLE_NAME"/>
</entity>
...
</entity-mappings>


Best Regards,
Chris
Re: orm.xml - customizing table name [message #740675 is a reply to message #740493] Tue, 18 October 2011 19:21 Go to previous messageGo to next message
Mauro Flores is currently offline Mauro FloresFriend
Messages: 84
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 19:22]

Report message to a moderator

Re: orm.xml - customizing table name [message #740684 is a reply to message #740675] Tue, 18 October 2011 19:35 Go to previous message
Mauro Flores is currently offline Mauro FloresFriend
Messages: 84
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.
Re: orm.xml - customizing table name [message #740686 is a reply to message #740675] Tue, 18 October 2011 19:35 Go to previous message
Mauro is currently offline MauroFriend
Messages: 79
Registered: July 2009
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.
Previous Topic:what maven artefact for (DynamicJaxbContext with xsd) ...jaxb.dynamic.metadata.SchemaMetadata
Next Topic:Problem with @OneToMany from an @Embeddable
Goto Forum:
  


Current Time: Tue Nov 25 21:12:15 GMT 2014

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

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