CriteriaBuilder cb = _entityManager.getCriteriaBuilder(); CriteriaQuery<Message> criteriaQuery = cb.createQuery(Message.class); Root<Message> messageRoot = criteriaQuery.from(Message.class); Root<Device> deviceRoot = criteriaQuery.from(Device.class); Fetch<Message, Device> recipientDeviceFetch = messageRoot.fetch("recipientDevice", JoinType.LEFT); Join<Message, Device> messageRecipientDeviceJoin = (Join<Message, Device>) recipientDeviceFetch; criteriaQuery.where(cb.and(messageRoot.get(Message.COLUMN_ID).in(messageIdsToDelete), cb.equal(deviceRoot.get(Device.COLUMN_PRIMARY_KEY), devicePrimaryKey))); criteriaQuery.select(cb.construct(Message.class, messageRoot.get("recipientDevice"), messageRoot.get(Message.COLUMN_CLIENT_MESSAGE_ID))); List<Message> messages = _entityManager.createQuery(criteriaQuery).getResultList(); return messages;
MappedSuperClass must be used to inherit properties, associations, and methods. Entity inheritance must be used when you have an entity, and several sub-entities. You can tell if you need one or the other by answering this questions: is there some other entity in the model which could have an association with the base class? If yes, then the base class is in fact an entity, and you should use entity inheritance. If no, then the base class is in fact a class that contains attributes and methods that are common to several unrelated entities, and you should use a mapped superclass. For example: You can have several kinds of messages: SMS messages, email messages, or phone messages. And a person has a list of messages. You can also have a reminder linked to a message, regardless of the kind of message. In this case, Message is clearly an entity, and entity inheritance must be used. All your domain objects could have a creation date, modification date and ID, and you could thus ...
Comments
Post a Comment