Best way to model Customer Address

I tend towards first approach for all the usual reasons of normalisation. This approach also makes it easier to perform data cleansing on mailing details. If you are possibly going to allow multiple addresses (mail, residential, etc) or wish to be able to use effective dates, consider this approach Customer (id, phys_address_id) Cust_address_type (cust_id, mail_address_id, … Read more

Hibernate sequence on oracle, @GeneratedValue(strategy = GenerationType.AUTO)

These Annotations are no creating two sequences, only one. Is this correct/expected? That’s the expected behavior. When using @GeneratedValue(strategy = GenerationType.AUTO), the JPA provider will pick an appropriate strategy for the particular database. In the case of Oracle, this will be SEQUENCE and, since you did not specify anything, Hibernate will use a single global … Read more

How to make an Inner Join in django?

You are probably looking for select_related, which is the natural way to achieve this: pubs = publication.objects.select_related(‘country’, ‘country_state’, ‘city’) You can check the resulting SQL via str(pubs.query), which should result in output along the following lines (the example is from a postgres backend): SELECT “publication”.”id”, “publication”.”title”, …, “country”.”country_name”, … FROM “publication” INNER JOIN “country” ON … Read more

How do you join two tables on a foreign key field using django ORM?

I’ve been working with django for a while now and I have had a pretty rough time figuring out the table joins, but I think I finally understand and I would like to pass this on to others so they may avoid the frustration that I had with it. Consider the following model.py: class EventsMeetinglocation(models.Model): … Read more

How to get next value of SQL Server sequence in Entity Framework?

You can create a simple stored procedure in SQL Server that selects the next sequence value like this: CREATE PROCEDURE dbo.GetNextSequenceValue AS BEGIN SELECT NEXT VALUE FOR dbo.TestSequence; END and then you can import that stored procedure into your EDMX model in Entity Framework, and call that stored procedure and fetch the sequence value like … Read more

Doing an “IN” query with Hibernate

The syntax of your JPQL query is incorrect. Either use (with a positional parameter): List<Long> ids = Arrays.asList(380L, 382L, 386L); Query query = em.createQuery(“FROM TrackedItem item WHERE item.id IN (?1)”); query.setParameterList(1, ids) List<TrackedItem> items = query.getResultList(); Or (with a named parameter): List<Long> ids = Arrays.asList(380L, 382L, 386L); Query query = em.createQuery(“FROM TrackedItem item WHERE item.id … Read more

How to map a map JSON column to Java Object with JPA

You can use a JPA converter to map your Entity to the database. Just add an annotation similar to this one to your params field: @Convert(converter = JpaConverterJson.class) and then create the class in a similar way (this converts a generic Object, you may want to specialize it): @Converter(autoApply = true) public class JpaConverterJson implements … Read more