native id generator [message #539060] |
Wed, 09 June 2010 10:08  |
Eclipse User |
|
|
|
Hi all,
I'm going to switch from Hibernate to EclipseLink in an exiting project. The old Hibernate mapping could be used with Oracle, MySQL, PostgreSQL and H2. And it used native id generator to automatically switch between databases with autoincrement support and databases with sequence support. Is there such a generator type in EclipseLink?
Thanks in advance,
Luca
|
|
|
|
Re: native id generator [message #539958 is a reply to message #539232] |
Mon, 14 June 2010 08:31   |
Eclipse User |
|
|
|
Hi Doug,
with Hibernate I had this situation
the MySQL DDL with auto_increment:
Create table attribute (
id_attribute Bigint NOT NULL AUTO_INCREMENT,
name Varchar(50) NOT NULL,
type Int NOT NULL,
UNIQUE (name),
Primary Key (id_attribute)) ENGINE = InnoDB;
the Oracle DDL with sequence:
CREATE SEQUENCE seq_attribute;
Create table attribute (
id_attribute Integer NOT NULL ,
name Varchar2 (50) NOT NULL UNIQUE ,
type Integer NOT NULL ,
primary key (id_attribute)
);
and the mapping of "native" type using auto_increment and cascading
to the configured sequence on database missing autoincrement feature
<hibernate-mapping>
<class name="org.spagic.metadb.model.Attribute" table="attribute">
<comment></comment>
<id name="idAttribute" type="java.lang.Long">
<column name="id_attribute" />
<generator class="native">
<param name="sequence">seq_attribute</param>
</generator>
</id>
...
</class>
</hibernate-mapping>
I'd like to do something simlar with EclipseLink
@Id
@NativeGenerator(name="ATTRIBUTE_GENERATOR", sequenceName="SEQ_ATTRIBUTE", allocationSize = 1)
@GeneratedValue(strategy=GenerationType.NATIVE, generator="ATTRIBUTE_GENERATOR")
@Column(name="ID_ATTRIBUTE")
private Long idAttribute;
and having it work with autoincrement or sequence of given name.
NATIVE is a name from Hibernate, this feature may already exist but I cannot
figure out how to annotate id's to get this behaviour.
The actual project is based on JPA standard, the previous, on Hibernate, wasn't.
Thanks,
Luca
[Updated on: Mon, 14 June 2010 09:06] by Moderator
|
|
|
|
|
Re: native id generator [message #541819 is a reply to message #539060] |
Tue, 22 June 2010 11:50  |
Eclipse User |
|
|
|
I believe AUTO will use IDENTITY on database platforms that support IDENTITY, and SEQUENCE or TABLE on those that do not.
You can configure a NativeSequence in code using a SessionCustomizer.
|
|
|
Powered by
FUDForum. Page generated in 0.27567 seconds