boyd4715
boyd4715

Reputation: 2729

Hibernate UserType to truncate trim data

Wondering if it is a good or bad ideal to make use of Hibernate UserType to trim data from an incoming data feed to prevent exceptions thrown if the data is to large to fit into the given column.

We receive data from a lot of data sources and have no control on the size of the data that is sent.

We are looking at about 100 fields in which we would need to create this for.

Upvotes: 1

Views: 1093

Answers (2)

Buck Fury
Buck Fury

Reputation: 41

A custom UserType seems like a more DRY solution than the setters approach. A validate method seems ugly too.

I'm looking for a better alternative to a custom UserType also but so far have not found one.

Upvotes: 4

hvgotcodes
hvgotcodes

Reputation: 120198

You don't need a custom UserType for this. Just put the logic on the Pojos that are being submitted, in the setters. Or create a validate() method that validates the state of the object and call that method before persisting.

Upvotes: 1

Related Questions