Allow enhanced.TableGenerator to segment itself per entity as default

Description

Currently TableGenerator use a static string ("default" ) for its default segment column name. The implication is that all TableGenerators defined without specifying a segment value explicitly ended up using the same row.

Where this cam up was in the case of annotations where the generator is attached to a base entity class.

Environment

None

Activity

Show:
Drew Kutcharian
November 13, 2008, 10:52 AM

I don't think prefer_entity_table_as_segment_value works with Hibernate Annotations.

In my entity I have:
@Id
@GenericGenerator(name = "idGenerator", strategy = "org.hibernate.id.enhanced.TableGenerator", parameters = {
@Parameter(name = "optimizer", value = "pooled"), @Parameter(name = "initial_value", value = "1"),
@Parameter(name = "increment_size", value = "10"), @Parameter(name = "prefer_entity_table_as_segment_value", value = "true") })
@GeneratedValue(generator = "idGenerator")
@Column(name = "id")
private Integer id = null;

But in the hibernate_sequences table, there's only one row with name "default" and all the entities use the next_val of that.

Please advise if you want a JIRA separate issue for this.

Thanks,

Drew

Drew Kutcharian
November 13, 2008, 7:27 PM

BTW, I'm using Hibernate 3.3.1.GA with Hibernate Annotations 3.4.0.GA

Steve Ebersole
November 14, 2008, 4:39 PM

I have tests showing this works w/o annotations, and just looked at the code for how annotations deals with this and I do not see any problems with it. Please make sure you are using the Hibernate Core version you think you are using

Drew Kutcharian
November 14, 2008, 7:10 PM

Steve,

I'm sure Hibernate versions are correct since:

1) I use Ivy to download the correct versions of libraries from JBoss Maven repository

2) As a workaround I created my own custom id generator that extends TableGenerator (com.foo.bar.IDGenerator) and all it does is it overrides the configure method as:
@Override
public void configure(final Type type, final Properties params, final Dialect dialect) throws MappingException {
params.put("optimizer", "pooled");
params.put("initial_value", "1");
params.put("increment_size", "10");
params.put("prefer_entity_table_as_segment_value", "true");
super.configure(type, params, dialect);
}

and in my entity I have:

@Id
@GenericGenerator(name = "idGenerator", strategy = "com.foo.bar.IDGenerator")
@GeneratedValue(generator = "idGenerator")
@Column(name = "id")
private Integer id = null;

and things work per spec.

I was worried I wasn't using the annotations correctly that's why I commented to this JIRA in the first place.

This is really strange.

cheers,

Drew

Steve Ebersole
March 21, 2011, 7:05 PM

Bulk closing stale resolved issues

Fixed

Assignee

Steve Ebersole

Reporter

Steve Ebersole

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure