java - How to check if object have been saved to database -
I am using Spring JDBC and I want to make a method that checks whether the database has been continued so far or not, which means that there will be an automatically increased key.
I have a code whose name is I can also determine if the object has been saved or not, but I did not want to do a query for it. I think the last option was to change the type of Is there a way to do this in the Domain Layer? to A good idea is considered: Frameworks of persistence such as PPAs encourage it (see this example and see through it). Using an object type immediately gives you an unreserved object to immediately check that In this way, you should have Adding a Business Key In a better approach, it is recommended to use a business key in additon for database-managed IDs. . The business key is an entity identifier, which, unlike the auto-generated primary key ( rental key ), has some meaning for the user ( natural key ). You should override the id is int since primitive entries are auto-assigned, if no other value is given, then I can make a method That checks for
id == 0 but then I have to make sure my primary key starts at sequence 1.
id to
integer and then check that it is
null but I Do not know that this is a good way to do this.
integer to replace
id
id == zero . Just for completeness:
id == null : saved object, a
INSERT
Id! = Null : the object has already been saved,
UPDATE
0 Also other integer values) meaning as a special case uninitialized ; You already have
null , which processes the idea of a special case properly.
par method to compare two objects using a professional key, and not a auto-generated primary key.
Comments
Post a Comment