Schema specified in @Table annotation should be passed as a parameter to the
SequenceGenerator generate method.
---------------------------------------------------------------------------------------------------------------
Key: HHH-5269
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5269
Project: Hibernate Core
Issue Type: Improvement
Components: core
Environment: Hibernate 3.4.0GA (bundled with JBoss5.1GA)
Reporter: Nico Mack
Priority: Minor
In the scope of a recent project built on JBoss5.1GA and using Oracle as a database we
came up with the following architecture. Since all our EJBs are going to need an Id, we
put the ID property in a class, called CoreEntityBean with the @MappedSuperclass
annotation. Here's what the getId method looks like:
@Id
@GeneratedValue(generator="my_gen")
@GenericGenerator(name = "my_gen", strategy =
"my_package.TableNameSequenceGenerator")
@Column(name = "id")
public Integer getId() {
return this.Id;
}
All our actual EJBs inherit from this CoreEntityBean, and are mapped using @Table
annotations to tables in different schemas:
@Entity
@Table(name = "info", schema = "core")
public class CoreInfo extends CoreEntityBean {
Our custom TableNameSequenceGenerator basically takes the name of the table and adds the
suffix "_seq" to determine the name of the sequence for the corresponding table.
All sequences have been created beforehand, in the same schema the corresponding table is
located.
Here's what the generate method of our TableNameSequenceGenerator looks like:
@Override
public void configure (Type p_Type, Properties p_Parameters, Dialect p_Dialect) throws
MappingException
{
String l_TableName;
String l_SequenceName;
String l_SchemaName;
l_SequenceName = p_Parameters.getProperty(SequenceGenerator.SEQUENCE);
if ((l_SequenceName == null) || (l_SequenceName.length() == 0))
{
l_TableName = p_Parameters.getProperty(PersistentIdentifierGenerator.TABLE);
l_SchemaName = p_Parameters.getProperty(PersistentIdentifierGenerator.SCHEMA);
if (l_TableName != null)
{
l_SequenceName = (l_SchemaName != null)?l_SchemaName + "." + l_TableName +
"_seq":l_TableName + "_seq";
p_Parameters.setProperty(SequenceGenerator.SEQUENCE, l_SequenceName);
m_Logger.log(Level.INFO, "Sequence Name = " + l_SequenceName);
}
}
super.configure (p_Type,p_Parameters,p_Dialect);
}
When single-stepping through the generate method, we came to realize that the SCHEMA
property was never set and as a consequence the db sequences are not found. I'm not
sure whether this issue has already been fixed in a later version or not. If not, I
thought it would be useful to add the schema to the properties passed to the
SequenceGenerator.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira