java - Check duplicate key before commit? -
Before doing my BeanFieldGroup with JPAContainer I'm looking for a solution to see a duplicate key. Is there a solution for this without using some solution? For example, when I execute commit a few ways to check that what exists in the key database and returns an exception?
I am trying this
@Entity @ table (name = "curriculum") implements the public class curriculum Serializable {Personal Static Final Long Serial VERSIONUID = 1L ; @ ID @ Generated Values Private Long ID Cracking; @ Email @notapply@notnale @ size (max = 250) @column (exclusive = true) private string email; } / ** Beanfield Group * / Private Final Beanfield Group & lt; Curriculum & gt; Binder = New Beanfield Group & lt; Curriculum & gt; (Course category); Private Final Course Vine = New Course (); / ** Data Source * / Personal Final Custom JPAContainer & lt; Curriculum & gt; Data source = new custom jpacantainer & lt; Curriculum & gt; (Course category); Personal Vertical Layout BuildLayout () {vLayout = New Vertical Layout (); VLayout.setMargin (true); VLayout.setSpacing (true); Binder.setItemDataSource (beans); From the field & lt ;? & Gt; Area = faucet; // Email Exclusive Key on the Database Field = Binder. Build and Stop ("Email", "Email", TextLover.Class); Email = (Texture) binder .getField ("email"); Email.setWidth ("350px"); email.setMaxLength (250); VLayout.addComponent (email); Return vLayout; } @ Override Public Wide Click Button (Click Event Event) {if ((event.getButton ()) == BTnSlawar} {try {binder.commit ()}} Grip (CommitException e) {Notification.show (e.getMessage () , Type.ERROR_MESSAGE); } {Try DataSource.ADNTTI (Bindor ITMDatasource). Beta ()); } Hold (exception e) {Notification.show (e.getMessage (), type.ERROR_MESSAGE); Return; }} After I do: Datasource AddEntity (binder.getItemDataSource (.) GetBean ()); If dataSource.AddEntity () does not work and executes a normal exception.
Any thoughts?
How do I check whether the email field is already committed without using the criteria already in the database,
Any ideas?
About (suggestions for Svetlyn Zarev ): binder.addCommitHandler (new CommitHandler) {@Override Public Commands Undeclared CommitEvent commitEvent} CommitException throws {string email = (string) committed Event.getFieldBinder (). GetField ("Email") GetValue (); EntityManager em = / * retrieve your EntityManager * /; List & amp; Lt ;? & Gt; Results = em.createQuery ("Choose the audičrikum from text, where email =?") .setParameter (1, email) .getResultList (); If throwing new CommitException ("Emails already exists");} Override throws public WAAD postcomment (Committee Committee event) commute offense {}} (results.size ()> gt; 0);
Comments
Post a Comment