How to introduce multi-column constraint with JPA annotations?

You can declare unique constraints using the @Table(uniqueConstraints = …) annotation in your entity class, i.e. @Entity @Table(uniqueConstraints={ @UniqueConstraint(columnNames = {“productId”, “serial”}) }) public class InventoryItem { … } Note that this does not magically create the unique constraint in the database, you still need a DDL for it to be created. But seems like … Read more

Mapping object to dictionary and vice versa

Using some reflection and generics in two extension methods you can achieve that. Right, others did mostly the same solution, but this uses less reflection which is more performance-wise and way more readable: public static class ObjectExtensions { public static T ToObject<T>(this IDictionary<string, object> source) where T : class, new() { var someObject = new … Read more

No mapping found for field in order to sort on in ElasticSearch

After digging more, I found the solution as given below. ignore_unmapped should be explicitly set to true in the sort clause. “sort” : [ { “rating”: {“order” : “desc” , “ignore_unmapped” : true} }, { “price”: {“order” : “asc” , “missing” : “_last” , “ignore_unmapped” : true} } ] For further information have a look … Read more

Mapping many-to-many association table with extra column(s)

Since the SERVICE_USER table is not a pure join table, but has additional functional fields (blocked), you must map it as an entity, and decompose the many to many association between User and Service into two OneToMany associations : One User has many UserServices, and one Service has many UserServices. You haven’t shown us the … Read more

How do you create nested dict in Python?

A nested dict is a dictionary within a dictionary. A very simple thing. >>> d = {} >>> d[‘dict1’] = {} >>> d[‘dict1’][‘innerkey’] = ‘value’ >>> d[‘dict1’][‘innerkey2’] = ‘value2’ >>> d {‘dict1’: {‘innerkey’: ‘value’, ‘innerkey2’: ‘value2’}} You can also use a defaultdict from the collections package to facilitate creating nested dictionaries. >>> import collections >>> … Read more