@Entity
とCrudRepository
を使用してMySQLデータベースにエントリを作成していますが、@ GeneratedValue(strategy = GenerationType.AUTO)が実行されて自動インクリメントを生成する場所が不思議でした値?hibernateで@GenerateValueを実行すると
@Entity
@Table(name = "all_contacts")
public class Contact {
//Ideally this would be set as foreign key to application's user schema
private long userId;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="contactid")
private long contactId;
@NotNull
private String name;
//getters and setters
}
//
public interface ContactRepository extends CrudRepository<Contact, Long> { }
私はそのゲッターを通じてcontactId
の値にアクセスしたいので、私は聞いて、私はContactRepository.save()
が呼び出されるまで待たなければならないのですか?