RuntimeException: Cannot map to SQL type when using composite key with association

Hi.

I tried to make a composite key following this example. The only difference between the example and my implementation is that I use an association with another entity’s id.

To be specific, I have an entity called Building with String id and then I have a Floor entity with composite id (FloorPK). The composite id contains an association many-to-one with Building and a String for the floor id.
I also have an entity called Room which has a composite key made up of one Floor association and a String id.

When I try to generate the database scripts I get an exception:

[12:54:08.254] Exception has been thrown by com.haulmont.studio.ui.app.c@34a2beee:
[12:54:08.255] java.lang.RuntimeException: Cannot map to SQL type:Floor [maintapp$Floor]

 at com.haulmont.studio.backend.ed.ddl.F.getMappedType(SourceFile:151)

 at com.haulmont.studio.backend.ed.ddl.D.getMappedType(SourceFile:47)

 at com.haulmont.studio.backend.ed.ddl.a.generateAlterColumn(SourceFile:1889)

 at com.haulmont.studio.backend.ed.ddl.T.a(SourceFile:838)

 at com.haulmont.studio.backend.ed.ddl.T.a(SourceFile:493)

 at com.haulmont.studio.backend.ed.ddl.T.a(SourceFile:177)

 at com.haulmont.studio.backend.ed.ddl.a.generateTableUpdates(SourceFile:514)

 at com.haulmont.studio.backend.ed.ddl.a.generateUpdates(SourceFile:503)

 at com.haulmont.studio.ui.d.H.c(SourceFile:135)

 at com.haulmont.studio.ui.d.H.b(SourceFile:109)

 at com.haulmont.studio.ui.d.J.buttonClick(SourceFile:190)

 at sun.reflect.GeneratedMethodAccessor96.invoke(Unknown Source)

 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

 at java.lang.reflect.Method.invoke(Method.java:498)

 at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)

 at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:200)

 at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:163)

 at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1037)

 at com.vaadin.ui.Button.fireClick(Button.java:377)

 ...
[12:54:08.260] Unexpected error
java.lang.RuntimeException: Cannot map to SQL type:Floor [maintapp$Floor]

I should also point out that whenever I try to see the DDL preview of Room entity in Cuba Studio it throws a NullPointerException.

Other info:

Studio version 6.8.2
Platform version 6.8.3
OS Windows 7

Hi
If you can prepare a sample app that will help.

Hi,
Which version of Studio do you use?
By your description, we have found a little bug, but it is not the issue you are observing.

The “Room” entity has the attribute of the “Floor” type. Right? Could you share the source code of the “Room” entity?
Or which is better, share the whole project. You can zipProject and attach it here or share the project on GitHub.

Unfortunately I cannot share the whole project. However, I made a separate project and isolated the entities that cause the exception. In this new project, I get the same exception as you get in that bug report (NullPointerException).

The “Room” entity has the attribute of the “Floor” type. Right?

Yes, that’s correct.
Also, I don’t know if it makes any difference but I’m using mssql server 2014 on the original project.
If it helps you with anything, I attach the new project: test.zip (75.3 KB)

Hi,
Thank you for your sample project. Did you try to assemble it? Building fails with the error: "
The mapping [floor] from the embedded ID class [class ro.umbono.test.entity.RoomPK] is an invalid mapping for this class."

EclipseLink does not support association attributes in embedded PK.
You can link Floor with Building outside the PK and make the association attribute mandatory and unique. Does the approach suit you?

I haven’t tried to assemble it before. I just ran it and it threw a null pointer exception without much explanation. I see the error now, after assembling it. Thanks for the suggestion.
About the associated attributes, that was the approach I was using before but I tried to make it for what it was: a composite primary key. I reverted to the old way. Thanks for your help.

A post was split to a new topic: The mapping [itemId] from the embedded ID class [class example.ItemInventoryCompositeKey] is an invalid mapping for this class