Specifying distinct sequence per table in Hibernate on subclasses
Have you tried doing it this way ?
@MappedSuperclass
public abstract class DataObject implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "idgen")
@Column(name = "id")
private int id;
}
@Entity
@SequenceGenerator(initialValue = 1, name = "idgen", sequenceName = "entityaseq")
@Table(name = "entity_a")
public class EntityA extends DataObject {
}
@Entity
@SequenceGenerator(initialValue = 1, name = "idgen", sequenceName = "entitybseq")
@Table(name = "entity_b")
public class EntityB extends DataObject {
}
I'm sorry I don't have the required environment to test it right now but I'll try it later.
Hibernate sequence, use the specific sequence
In hibernate you can specify the used seq explicitly by using the annotations
@Id
@Column(name = "COLUMN_NAME", nullable = false)
@GeneratedValue(strategy = AUTO, generator = "yourEntitySeqGen")
@SequenceGenerator(name = "yourEntitySeqGen", sequenceName = "SEQUENCE_NAME_IN_YOUR_DATABASE")
cheers
How to use a Sequence which is not bound to a specific table with Entity Framework code-first?
Found the solution myself. Just execute this on database creation:
context.Database.ExecuteSqlCommand("CREATE SEQUENCE TestSequence AS int START WITH 1 INCREMENT BY 1;");
Make @GeneratedValue start a sequence with a specific value
You can define your entity like this:
@Entity
@Table(name = "users")
@SequenceGenerator(name = "sequence", sequenceName = "mySequence")
public class User {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequence")
@Getter private Long id;
And then in your .sql file write insert queries like this:
INSERT INTO users values (select nextval('mySequence'), ...
select nextval('mySequence')
will give you next available value from sequence table
Issue with sequence why two entity are sharing the same sequence when generating schema with hbm2ddl ?
You are using the Global sequence generator that hibernate provide by default when no generator is provided as specifed by the JPA Spec. To have a private generator you should declare a private generator with the annotation @SequenceGenerator
and set the generator
attribute of the @GeneratedValue
annotation
Extracted from javadoc
@GeneratedValue
(Optional) The name of the primary key generator to use as specified
in the SequenceGenerator or TableGenerator annotation.Defaults to the id generator supplied by persistence provider.
SequenceGenerator
This annotation defines a primary key generator that may be referenced by name when a
generator element is specified for the GeneratedValue annotation. A
sequence generator may be specified on the entity class or on the
primary key field or property. The scope of the generator name is
global to the persistence unit (across all generator types).Example:
@SequenceGenerator(name="EMP_SEQ", sequenceName="private_sequence")
Hibernate recommends that new projects use hibernate.id.new_generator_mappings=true as the new generators are more efficient and closer to the JPA 2 specification semantic
Section 1.3. Properties
2.2.3. Mapping identifier properties
Complete example
@Entity
@SequenceGenerator(name="PRIVATE_SEQ", sequenceName="private_sequence")
public class test {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="PRIVATE_SEQ")
Long id;
}
Google DialogFlow -- Number-Sequence entity only matches SPECIFIC length of characters
The built-in entities like @sys.number-sequence
will help you in finding numbers in sequence only. In api.ai, you can not specify the length of a number that you want either 4-digit or 6-digit. In addition, training agent for all permutations of any digit number is not a generalized solution.
What you can do is write a webhook, fetch this parameter @sys.number-sequence
in your code & put a verification over there. If it is not of the number of digits you want, you can send a reply saying Please enter 6 digit number
or say you have entered a correct code
.
Related Topics
How to Speed Up This Indexed View
SQL Sum Field When Column Values Match
How to Subtract Two Row's Values Within Same Column Using SQL Query
How to Make a List of T-SQL Results with Comma's Between Them
How to Call a Stored Procedure from Another Stored Procedure
Blank Values in Date Column Returning as 1900/01/01 on Running Select Statement
How to Change the Name of the Athena Results Stored in S3
How to Find Duplicate Consecutive Values in This Table
Oracle SQL Returns Rows in Arbitrary Fashion When No "Order By" Clause Is Used
Sync Between SQL Server and MySQL Server
How to Retrieve Same Column Twice with Different Conditions in Same Table
SQL Query with Union in Doctrine Symfony
Filter Duplicate Rows Based on a Field
Executing a Stored Procedure Within a Stored Procedure
Is There a Tool for Refactoring SQL, a Bit Like a Resharper for SQL