Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Not Answered
Replies
19 replies
Subscribers
9 subscribers
Views
11788 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
General
Hi, I wonder if I could preset the id of a record to start with 1000 instead of
Will Teoh
over 11 years ago
Hi, I wonder if I could preset the id of a record to start with 1000 instead of 1 when it stores to the database table? Anything to add into the codes below to make that happen?? Thanks
<xsd:annotation>
<xsd:appinfo source="appian.jpa">
@Id
@GeneratedValue
</xsd:appinfo>
</xsd:annotation>...
OriginalPostID-95347
OriginalPostID-95347
Discussion posts and replies are publicly visible
0
garym
over 11 years ago
Hi, is there an equivalent for SQL server or do we just make the primary key an auto-increment type?
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Eduardo Fuentes
Appian Employee
over 11 years ago
SQL Server doesn't support SequenceGenerator, in that case you can simply use @GeneratedValue if you want to have a PK of auto-increment type.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
garym
over 11 years ago
Hi Eduardo, does the field have to be set up as PRIMARY AUTO-INCREMENT in SQL server?
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Eduardo Fuentes
Appian Employee
over 11 years ago
Yes if using the @GeneratedValue annotation
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
garym
over 11 years ago
Is using the @GeneratedValue annotation and setting up the PK of auto-increment considered best practice or is there another preferred way of acheiving this?
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
garym
over 11 years ago
I meant best practice for SQL server DBs
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Eduardo Fuentes
Appian Employee
over 11 years ago
If your use case requires an autoincrement primary key then this is the right approach; more than a best practice it depends on whether this type of primary key fits your needs.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
guozhangy
over 10 years ago
Hi Eduardo,
About your solution, I have some questions:
What is mysequence? Is it an existing sequence from Oracle? If it is, shouldn’t the initialValue be managed by the database?
Or is the sequence generated and managed by APPIAN and it has nothing to do with database?
According to JPA API: sequenceName is The name of the database sequence object from which to obtain primary key values. Because you didn't specify sequenceName, how do they know which sequence object from database to use?
Thanks.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Eduardo Fuentes
Appian Employee
over 10 years ago
This is creating a sequence generator where the initial value should be 1,000 and its name is MY_SQ and will increment by 1 (since not using any value for the allocationSize attribute). More details on each of these three arguments (name, initialValue and allocationSize at
docs.oracle.com/.../SequenceGenerator.html).
In the second line I declare that my primary key is going to be using a sequence that will get its configuration from a generator previously defined as MY_SQ
@SequenceGenerator(name="MY_SQ", initialValue=1000)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="MY_SQ")
You may want to delete the sequence from MySQL and republish the data store to see if that helps.
When you click on the "Verify Data Store" button see if you can download the DDL to make sure the sequence is going to be created correctly with the initial value set to the specified number
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
<