Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DefaultRecordUnmapper cannot unmap a POJO into its corresponding UDTRecord #6917

Closed
nsn opened this issue Dec 14, 2017 · 9 comments
Closed

Comments

@nsn
Copy link

nsn commented Dec 14, 2017

Expected behavior and actual behavior:

Expected: generated POJOs for Postgres custom types should be usable in generated DAOs
Actual: org.jooq.impl.DAOImpl.insert throws a MappingException

Steps to reproduce the problem:

  1. create custom type
  2. create table using the new type
  3. generate POJOs and DAOs using the default generator and strategy
  4. call dao.insert(pojo) and observe error

I've created a small maven project to demonstrate, see the attached zip file
jooqmve-master.zip, or clone
https://github.com/nsn/jooqmve

Versions:

  • jOOQ: 3.10.0
  • Java: 1.8.0_25 on both Mac and Ubuntu
  • Database (include vendor): postgres (PostgreSQL) 10.1
  • JDBC Driver (include name if inofficial driver): org.postgresql.postgresql 42.1.4
@lukaseder
Copy link
Member

Thank you very much for your report. Would you mind posting the stack trace as well here, for completeness' sake?

@nsn
Copy link
Author

nsn commented Dec 14, 2017

gladly:

org.jooq.exception.MappingException: An error ocurred when mapping record from class com.nightspawn.jooq.pgsqlcustomtype.generated.tables.pojos.MyTable
	at org.jooq.impl.DefaultRecordUnmapper$PojoUnmapper.unmap(DefaultRecordUnmapper.java:238)
	at org.jooq.impl.DefaultRecordUnmapper.unmap(DefaultRecordUnmapper.java:96)
	at org.jooq.impl.AbstractRecord.from0(AbstractRecord.java:794)
	at org.jooq.impl.AbstractRecord.from(AbstractRecord.java:824)
	at org.jooq.impl.DefaultDSLContext$6.operate(DefaultDSLContext.java:3674)
	at org.jooq.impl.RecordDelegate.operate(RecordDelegate.java:122)
	at org.jooq.impl.DefaultDSLContext.newRecord(DefaultDSLContext.java:3670)
	at org.jooq.impl.DAOImpl.records(DAOImpl.java:412)
	at org.jooq.impl.DAOImpl.insert(DAOImpl.java:171)
	at org.jooq.impl.DAOImpl.insert(DAOImpl.java:147)
	at com.nightspawn.jooq.pgsqlcustomtype.MainClass.main(MainClass.java:43)
	... 6 more
Caused by: org.jooq.exception.DataTypeException: Cannot convert from MyCustomType (single, 1) (class com.nightspawn.jooq.pgsqlcustomtype.generated.udt.pojos.MyCustomType) to class com.nightspawn.jooq.pgsqlcustomtype.generated.udt.records.MyCustomTypeRecord
	at org.jooq.tools.Convert$ConvertAll.fail(Convert.java:1169)
	at org.jooq.tools.Convert$ConvertAll.from(Convert.java:1058)
	at org.jooq.tools.Convert.convert0(Convert.java:315)
	at org.jooq.tools.Convert.convert(Convert.java:307)
	at org.jooq.tools.Convert.convert(Convert.java:379)
	at org.jooq.impl.DefaultDataType.convert(DefaultDataType.java:741)
	at org.jooq.impl.Tools.setValue(Tools.java:2266)
	at org.jooq.impl.DefaultRecordUnmapper$PojoUnmapper.unmap(DefaultRecordUnmapper.java:226)
	... 16 more

@lukaseder
Copy link
Member

Thanks again for your nice minimal test case. I can reproduce the issue and the stack trace. Will now look into this.

@lukaseder lukaseder changed the title error while mapping POJOs for Postgres custom types DefaultRecordUnmapper cannot unmap a POJO into its corresponding UDTRecord Dec 15, 2017
@lukaseder
Copy link
Member

This doesn't seem strictly dependent on using DAOs. It simply doesn't work with any way the DefaultRecordUnmapper is invoked (including Record.from(Object))

@lukaseder
Copy link
Member

Indeed, recursive unmapping is simply not supported at this moment. Will look more into this next week.

@lukaseder
Copy link
Member

The relevant integration test is no longer failing due to a recent fix. There had been a few RecordMapper, RecordUnmapper, and ConverterProvider related fixes in the recent past. Will investigate what might have fixed it, specifically.

@lukaseder
Copy link
Member

It looks like the test should have passed a while ago already, but because the integration tests didn't turn on generating equals() and hashCode() by default, and we switched the default for the <pojosEqualsAndHashCode/> flag just recently, #13137, the test no longer fails.

I'm closing this issue as fixed

@lukaseder
Copy link
Member

I tried again with the MCVE, the issue still persists:

Exception in thread "main" org.jooq.exception.MappingException: An error ocurred when mapping record from class com.nightspawn.jooq.pgsqlcustomtype.generated.tables.pojos.MyTable
	at org.jooq.impl.DefaultRecordUnmapper$PojoUnmapper.unmap(DefaultRecordUnmapper.java:239)
	at org.jooq.impl.DefaultRecordUnmapper.unmap(DefaultRecordUnmapper.java:102)
	at org.jooq.impl.AbstractRecord.from0(AbstractRecord.java:916)
	at org.jooq.impl.AbstractRecord.from(AbstractRecord.java:927)
	at org.jooq.impl.DefaultDSLContext.lambda$44(DefaultDSLContext.java:4443)
	at org.jooq.impl.RecordDelegate.operate(RecordDelegate.java:144)
	at org.jooq.impl.DefaultDSLContext.newRecord(DefaultDSLContext.java:4442)
	at org.jooq.impl.DAOImpl.records(DAOImpl.java:472)
	at org.jooq.impl.DAOImpl.insert(DAOImpl.java:180)
	at org.jooq.impl.DAOImpl.insert(DAOImpl.java:156)
	at com.nightspawn.jooq.pgsqlcustomtype.MainClass.main(MainClass.java:45)
Caused by: org.jooq.exception.DataTypeException: Cannot convert from MyCustomType (single, 1) (class com.nightspawn.jooq.pgsqlcustomtype.generated.udt.pojos.MyCustomType) to class com.nightspawn.jooq.pgsqlcustomtype.generated.udt.records.MyCustomTypeRecord
	at org.jooq.impl.Convert$ConvertAll.fail(Convert.java:1473)
	at org.jooq.impl.Convert$ConvertAll.from(Convert.java:1323)
	at org.jooq.impl.Convert.convert0(Convert.java:432)
	at org.jooq.impl.Convert.convert(Convert.java:507)
	at org.jooq.impl.AbstractDataType.convert(AbstractDataType.java:599)
	at org.jooq.impl.DefaultDataType.convert(DefaultDataType.java:1)
	at org.jooq.impl.Tools.setValue(Tools.java:3193)
	at org.jooq.impl.DefaultRecordUnmapper$PojoUnmapper.unmap(DefaultRecordUnmapper.java:229)
	... 10 more

Perhaps the integration test was testing something else

@lukaseder
Copy link
Member

I see now. The improvements that fixed the problem here were:

Both were implemented in jOOQ 3.15.0. Closing this as a duplicate of the above two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

2 participants