POJO to Record Problem

402 views
Skip to first unread message

jonas.jh...@gmail.com

unread,
Apr 10, 2014, 1:13:40 PM4/10/14
to jooq...@googlegroups.com
Hey,

I am trying to convert a simple POJO into a Record by using the JPA @Column annotation, however JOOQ doesn't take the values.


Here is my sql table:

create table security_roles (
  id                        bigint not null auto_increment,
  role_name                 varchar(255));


And here is my class:

public class SecurityRole implements Role {

private Long id;
private String roleName;
public SecurityRole() {
}
@ConstructorProperties({ "id", "role_name" })
public SecurityRole(Long id, String roleName) {
this.id = id;
this.roleName = roleName;
}
public SecurityRolesRecord getAttachedRecord() {
return UserHelper.dsl().newRecord(Tables.SECURITY_ROLES, this);
}

@Override
@Column(name="role_name")
public String getName() {
return this.roleName;
}
public void setName(String roleName) {
this.roleName = roleName;
}

@Column(name="id")
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}
}

The resulting Record shows NULL for both values although the roleName is set.
Any ideas what I did wrong here?

Rob Sargent

unread,
Apr 10, 2014, 2:30:56 PM4/10/14
to jooq...@googlegroups.com

Don't you need an @Table?
--
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 jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jonas.jh...@gmail.com

unread,
Apr 10, 2014, 10:38:22 PM4/10/14
to jooq...@googlegroups.com
I tried it with @Table but it didn't work either.
I actually specifiy the table explicitly here: "return UserHelper.dsl().newRecord(Tables.SECURITY_ROLES, this);"

Somehow, jooq doesn't recognize the getters with the @Column annotation.

Jonas

unread,
Apr 11, 2014, 11:33:54 AM4/11/14
to jooq...@googlegroups.com, jonas.jh...@gmail.com
Apparently, it is also not working the other way round.
The fetched SecurityRolesRecord is filled however I can't map it into my SecurityRole class like this:
"record.into(SecurityRole.class);"

Do I miss something essential here?

Thanks a lot for helping me out with this.

Warm regards,
Jonas

Lukas Eder

unread,
Apr 11, 2014, 11:42:58 AM4/11/14
to jooq...@googlegroups.com, jonas.jh...@gmail.com
Hi Jonas,

Just checking: You're using lower-case column names in your @Column annotations. Do they match the generated Fields' names?

Cheers
Lukas


--

jonas.jh...@gmail.com

unread,
Apr 11, 2014, 12:12:14 PM4/11/14
to jooq...@googlegroups.com, jonas.jh...@gmail.com
Hi Lukas, yes, everything is lowercase and divided by underscore.
Do I have to let jooq generate the POJOs or should it also work with own POJOs?

jonas.jh...@gmail.com

unread,
Apr 12, 2014, 4:44:09 AM4/12/14
to jooq...@googlegroups.com, jonas.jh...@gmail.com
I found the problem! The column names were indeed not lowercase although I specified it that way. Apparently, the h2 default settings set column names to uppercase.
Is there a way to let JOOQ know to handle the conversion case-insensitive?



On Friday, April 11, 2014 11:42:58 PM UTC+8, Lukas Eder wrote:

Lukas Eder

unread,
Apr 12, 2014, 9:34:04 AM4/12/14
to jooq...@googlegroups.com
Hi Jonas,

Good find. As many users have been running into this issue - especially when writing vendor-agnostic applications, we're going to be supporting optional case-insensitivity soon:

This is a major task, however, as the complete jOOQ API would then need to switch from the current case-sensitive access patterns to case-insensitive ones. We're not quite sure how to configure that yet, as methods on generated classes like MY_TABLE.getName() would be affected by this new runtime setting.

Note: the existing RenderNameStyle Setting allows you to specify how jOOQ renders such names / identifiers in SQL statements:

In the mean time, it is always a good idea to keep in control of case sensitivity already in your DDL statements, by specifying, for example:

CREATE TABLE "MY_TABLE" (
  "MY_COLUMN" INT, 
  ...
)

Take MySQL's MyISAM storage engine, for instance. Tables are mapped to files on your file system, which are implicitly case-sensitive on *nix machines, or case-insensitive on Windows machines. Some databases (e.g. MySQL, PostgreSQL) report case-insensitive identifiers as lower-case, others (H2, HSQLDB, Oracle, ...) report them as upper-case from database meta information tables.

Again. Leaving these things to the "database gods" will only end up in tears :-)

Hope this helps,
Lukas
Reply all
Reply to author
Forward
0 new messages