OK, let's split threads in two. These discussions always get very confusing if you mix topics in a single thread.
2014/1/18 sergivs <[email protected]> > Hi Lukas, > > On Friday, January 17, 2014 11:46:35 AM UTC-8, Lukas Eder wrote: >> >> Hi Sergei, >> >> 2014/1/17 sergivs <[email protected]> >> >> Hi all, >>> >>> I'm just starting to use jOOQ and the first thing that I did was >>> basically something like this (after creating bindings with the generation >>> tool): >>> >>> MyRecord myRecord = dslContext.newRecord(MYTABLE, pojo); >>> >>> dslContext.execteInsert(myRecord); >>> >>> It's very convenient, but if the POJO does not have a field/getter >>> method/annotation matching a given field, then the field simply will not be >>> updated. Is there a way to force the insert/update to fail if a field >>> cannot be found (other than making the field NOT NULL in the schema, which >>> would be a hack and wouldn't work for updates, anyway)? >>> >> >> One thing that comes to mind is to implement a RecordListener, which can >> listen on insertStart() events: >> http://www.jooq.org/doc/3.2/manual/sql-execution/crud- >> with-updatablerecords/crud-record-listener/ >> >> I'm not sure if I correctly understood your requirements, but if you want >> to check if any Record field value is NULL prior to executing an insert, >> that would certainly be an option. >> >> > > This isn't exactly what I'm trying to do. Let me illustrate with an > example. > > Suppose there us a table called Balloons with the fields BalloonId > (primary key), Size (null permitted), and Color (null permitted). > > We create a class called Baloon that has methods getBalloonId(), > getSize(), getColour(). Note the different spelling. Now, the colour may or > may not be null, but if we create a record using DSLContext.newRecord(), > the Color field will always be null and the error will go unnoticed until > someone actually looks at the table data. Another example: we add a column > called Shape but forget to add a corresponding method in the class. > > Of course, if we coded every field and value pair by hand, for example, we > wouldn't have these problems, but this flexibility doesn't have to be > error-prone. There could be a policy or a flag that would determine whether > there must be a corresponding field/method/annotation for every known field > in the record that we are trying to generate from the POJO. It wouldn't be > so difficult to add this, but I don't want to reinvent the wheel. Perhaps, > this functionality is already there? > There is no such alerting / error reporting feature in jOOQ. However, if you're fine by using jOOQ's generated POJOs, then you may work around typos in the getters / setters? http://www.jooq.org/doc/3.2/manual/code-generation/codegen-pojos/ Another option is to write your own mappers using third-party tools, such as ModelMapper. -- You received this message because you are subscribed to the Google Groups "jOOQ User Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
