I seemed to work around it by overriding the save method, I'm sure there is a better way, I am open to suggestions.
BaseRepository
@NoRepositoryBean
interface BaseRepository<T, ID extends Serializable> extends Repository<T, Long> {
@RestResource(path="byIdIn",rel="byIdIn")
@Query("select r from #{#entityName} r where r.id in :q")
Page<T> findByIdIn(@Param("q") List<Long> q, Pageable pageable)
Page<T> findAll(Pageable pageable)
T findOne(ID id)
T save(T entity)
T delete(ID id)
}
ContactRepository
@RepositoryRestResource(collectionResourceRel="contacts", path="contacts")
interface ContactRepository extends BaseRepository<Contact, Long>, ContactRepositoryCustom {
}
ContactRepositoryCustom
interface ContactRepositoryCustom {
public <S extends Contact> S save(S entity)
}
ContactRepositoryImpl
@NoRepositoryBean
class ContactRepositoryImpl implements ContactRepositoryCustom {
@PersistenceContext
private EntityManager em
@Transactional
@Override
public <S extends Contact> S save(S entity) {
Contact contact = entity as Contact
try {
em.persist(contact)
contact.getComment().each {
Comment comment = new Comment(contact, it)
em.persist(comment)
}
} catch (Exception e) {
println e
}
return contact
}
}
This is just a sample, it needs some cleaning up, but I have the save() method working as expected. I just don't want to over do it if there is a baked in way in Spring Data / Spring Data Rest to do this kind of thing with annotations without having to roll a solution like this. I searched through the docs and online, but did not find a solution. I may have overlooked something, not sure.