Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

shaiwolf avatar image
shaiwolf asked Erick Ramirez edited

Driver 4.x Mapper problem with UDT

I managed to migrate the project's code from driver version 3.x to 4.x.

However when process initializes the DAOs I get the error below.

It seems that the auto generated code is trying to locate the UDT's fields inline as entity columns.

2021-11-21 10:41:53,805 [localhost-startStop-1] FATAL esEngine.ProfilesEngineServlet  - ProfilesEngineServlet Failed to init due to exception
java.lang.IllegalArgumentException: The CQL ks.table: proj.profile has missing columns: [partner_id, campaign_id] that are defined in the entity class: com.proj.bean.Campaign
        at com.proj.bean.CampaignHelper__MapperGenerated.validateEntityFields(CampaignHelper__MapperGenerated.java:199)
        at com.proj.cql3client.daoimpl.ProfileAccessorImpl__MapperGenerated.initAsync(ProfileAccessorImpl__MapperGenerated.java:1216)
        at com.proj.cql3client.daoimpl.ProfileAccessorImpl__MapperGenerated.init(ProfileAccessorImpl__MapperGenerated.java:1710)
        at com.proj.cql3client.MainDaoMapperImpl__MapperGenerated.lambda$profileAccessor$28(MainDaoMapperImpl__MapperGenerated.java:241)
        at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
        at com.proj.cql3client.MainDaoMapperImpl__MapperGenerated.profileAccessor(MainDaoMapperImpl__MapperGenerated.java:241)
        at com.proj.cql3client.daoimpl.ProfileDao.<init>(ProfileDao.java:67)

I have a profile entity containing a list of campaigns:

@Entity
@CqlName ("profile")
public class Profile {
   ...
   @CqlName("campaigns")
   private List<Campaign> campaigns;
   ...
}

Campaign is a user defined type:

@Entity
@CqlName ("campaign")
public class Campaign {
    ...
    @CqlName("partner_id")
    private int partnerId;


    @CqlName("campaign_id")
    private int campaignId;
    ...
}

In cassandra campaign type is defined:

CREATE TYPE campaign (
    partner_id int,
    campaign_id int
);

and the profile table is defined:

CREATE TABLE profile (
    ...
    campaigns list<frozen<campaign>>,
    ...
)

Registering a codec didn't solve the problem.

Does anyone know how to solve this issue?

Thanks,

Shai

java driveruser-defined type
1 comment
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Hi,

Any idea guys?

Shai

0 Likes 0 ·

1 Answer

absurdfarce avatar image
absurdfarce answered Erick Ramirez edited

Hey @shaiwolf , thanks for posting!

I tried to reproduce the errors you describe but was unable to do so. I tried to use as much as possible from your sample code above but my sample code worked with UDTs out of the gate. I've pushed my sample to Github at https://github.com/absurdfarce/java-driver-mapper-udt. Feel free to take a look and let me know if there's something substantially different between what I'm doing and what your code is doing.

An additional question: what version of the Java driver are you using? My sample uses 4.13.0 (which is quite recent) but if you're using something older in the 4.x line it's certainly possible that you could be hitting an earlier bug that's since been resolved. I'd like to test my impl with the precise version of the Java driver you're using so please let me know!

Thanks again!

Bret

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.