mapstruct issue with nested entities when mapping - spring

Hello I have the Following mapstruct mapping description.
#Mapper(componentModel = "spring", uses = {
GroupResolver.class }, unmappedTargetPolicy = ReportingPolicy.IGNORE, unmappedSourcePolicy = ReportingPolicy.IGNORE)
public abstract class GroupMapper {
#Autowired
private UserMapper userMapper;
#Autowired
private ChainMapper chainMapper;
#Mapping(target = "id", source = "id")
#Mapping(target = "name", source = "name")
#Mapping(target = "chains", expression = "java(mapChain(group))")
#Mapping(target = "users", expression = "java(mapUsers(group))")
public abstract GroupResp toModel(final Group group);
public Set<ChainResp> mapChain(final Group group) {
return chainMapper.toModelSet(group.getChains());
}
public Set<UserResp> mapUsers(final Group group) {
return userMapper.toModelSet(group.getUsers());
}
#Mapping(target = "id", source = "id")
#Mapping(target = "name", source = "name")
#Mapping(target = "chains", ignore = true)
#Mapping(target = "users", ignore = true)
#Mapping(target = "users.chainUnixPaths" , ignore = true )
public abstract Group toEntity(final GroupResp groupeResp);
public Set<Chain> mapChains(final GroupResp groupeResp) {
return chainMapper.toEntitySet(groupeResp.getChains());
}
public Set<User> mapUsers(final GroupResp groupeResp) {
return userMapper.toEntitySet(groupeResp.getUsers());
}
}
I m facing a compile time error stating that :
No target bean properties found: can't map Collection element "UnixPathResp users[].chainUnixPaths" to "UnixPath users[].chainUnixPaths". Consider to declare/implement a mapping method: "UnixPath map(UnixPathResp value)".
AND
No target bean properties found: can't map property "ServerResp users[].server" to "Server users[].server". Consider to declare/implement a mapping method: "Server map(ServerResp value)".
I assume that my Ignores are not Working Or my resolver is somehow fuzy.
Here is all related classes
#Entity
#Table(name = "groups")
public class Group implements Serializable {
private static final long serialVersionUID = 6980925916410978160L;
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_GROUPS")
#SequenceGenerator(name = "SEQ_GROUPS", sequenceName = "SEQ_GROUPS")
#Column(name = "GROUP_ID")
private Long id;
#Column(name = "GROUP_NAME", length = 256, nullable = false)
private String name;
#ManyToMany(fetch = FetchType.LAZY)
#JoinTable(name = "CHAIN_GROUP", joinColumns = #JoinColumn(name = "GROUP_ID"), inverseJoinColumns = #JoinColumn(name = "CHAIN_ID"))
private Set<Chain> chains = new HashSet<>();
#ManyToMany(fetch = FetchType.LAZY)
#JoinTable(name = "USER_GROUP", joinColumns = #JoinColumn(name = "GROUP_ID"), inverseJoinColumns = #JoinColumn(name = "USER_ID"))
private Set<User> users = new HashSet<>();
AND
public class GroupResp implements Serializable{
/**
*
*/
private static final long serialVersionUID = 7184268214689299357L;
#JsonProperty("GROUP_ID")
private Long id;
#NotBlank
#JsonProperty("GROUP_NAME")
private String name;
#JsonProperty("CHAIN_GROUP")
private Set<ChainResp> chains = new HashSet<>();
#JsonProperty("USER_GROUP")
private Set<UserResp> users = new HashSet<>();
Then my Generic Resolver
#Component
public class GroupResolver extends GenericPFResolveContract<GroupResp, Group, Long> {
#Override
public Long getIdof(GroupResp s) {
return s.getId();
}
#Override
#ObjectFactory
public Group resolve(GroupResp s,#TargetType Class<Group> ts) throws InstantiationException, IllegalAccessException {
return super.resolve(s, ts);
}
}
With
#Component
public abstract class GenericPFResolveContract<S,T,K> implements PFResolveContract<T, S> {
#Autowired
protected JpaRepository<T, K> sourceRepository;
#Override
#ObjectFactory
#Transactional
public T resolve(S s,#TargetType Class<T> ts) throws InstantiationException, IllegalAccessException {
if(s == null || getIdof(s) == null) {
return ts.newInstance();
}
return sourceRepository.findById(getIdof(s)).orElseGet(()-> {
T newInstance = null;
try {
newInstance = ts.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
return newInstance;
} );
}
public abstract K getIdof(S s);
}

Related

MapStruct doesn't convert right from List<Integer> ids to List<Product>

I have an Order entity which looks like this
#Entity
#JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
#Table(name = "orders")
public class Order {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column
private int id;
#Enumerated(EnumType.STRING)
#Column(name = "order_status")
private OrderStatus status;
#ManyToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.DETACH, CascadeType.REFRESH})
#JoinTable(name = "order_product"
,joinColumns = #JoinColumn(name = "order_id")
,inverseJoinColumns = #JoinColumn(name = "product_id"))
private List<Product> productList;
#ManyToOne
#JoinColumn(name = "user_id")
private User user;
#Column(name = "ordered_at")
private LocalDateTime orderTime;
#OneToOne
#JoinTable(name = "order_payment"
,joinColumns = #JoinColumn(name = "order_id",referencedColumnName = "id")
,inverseJoinColumns = #JoinColumn(name = "payment_id", referencedColumnName = "id"))
private Payment payment;
#ManyToOne
#JoinColumn(name = "shop_id")
private Shop shop;
...
contsructor getter and setters
}
OrderPostDto
public class OrderPostDto {
private int id;
private OrderStatus status;
private int userId;
private LocalDateTime orderTime;
private List<Integer> productIds;
private int shopId;
...
constructor getter and setters
}
MapStruct OrderMapper
#Mapper(componentModel = "spring", injectionStrategy = InjectionStrategy.CONSTRUCTOR, uses = {ProductService.class, ShopService.class, UserService.class})
public interface OrderMapper {
OrderMapper INSTANCE = Mappers.getMapper(OrderMapper.class);
OrderDto orderToDto(Order order);
#Mapping(source = "userId", target = "user")
#Mapping(source = "productIds", target = "productList")
#Mapping(source = "shopId", target = "shop")
Order dtoToOrder(OrderPostDto dto);
}
As you can see the OrderDto accepts Product ids as Integers and OrderMapper should Map them to the object from database table of products. But it generates code like this:
protected List<Product> integerListToProductList(List<Integer> list) {
if ( list == null ) {
return null;
}
List<Product> list1 = productService.getAllProducts();
for ( Integer integer : list ) {
list1.add( productService.getProductById( integer.intValue() ) );
}
return list1;
}
But for some reason it creates list1 which contains all the items from database List<Product> list1 = productService.getAllProducts();
But I need to achieve this behaviour List<Product> list1 = new ArrayList<>(list.size()); How do I make it generate this way?
I've solved my issue, I just defined mapper as an abstract class with implementation of this particular method. So it will look like this:
#Mapper(componentModel = "spring", injectionStrategy = InjectionStrategy.CONSTRUCTOR, uses = {ProductService.class, ShopService.class, UserService.class})
public abstract class OrderMapper {
#Autowired
protected ProductService productService;
public abstract OrderDto orderToDto(Order order);
#Mapping(source = "userId", target = "user")
#Mapping(source = "productIds", target = "productList")
#Mapping(source = "shopId", target = "shop")
public abstract Order dtoToOrder(OrderPostDto dto);
public List<Product> integerListToProductList(List<Integer> list) {
if ( list == null ) {
return null;
}
List<Product> list1 = new ArrayList<>(list.size());
for ( Integer integer : list ) {
list1.add( productService.getProductById( integer.intValue() ) );
}
return list1;
}
}

How to do a ManyToMany relationship insert

I am studying spring boot data using this API SWAPI, I did almost things but now I dont know how to map the relationship about two lists, above you can see my code and entities.
Entity Film
#Data
#Entity
public class Film extends Persistent<Long> {
private String title;
#JsonProperty(value = "episode_id")
private int episodeId;
#JsonProperty(value = "opening_crawl")
#Column(columnDefinition = "CLOB")
private String openingCrawl;
private String director;
private String producer;
#JsonDeserialize(converter = StringToLocalDateConverter.class)
#JsonProperty(value = "release_date")
private LocalDate releaseDate;
#JsonDeserialize(converter = ApiURLToEntitiesConverter.class)
#ManyToMany(mappedBy = "films")
private List<Person> characters;
#JsonDeserialize(converter = StringToLocalDateTimeConverter.class)
private LocalDateTime created;
#JsonDeserialize(converter = StringToLocalDateTimeConverter.class)
private LocalDateTime edited;
private String url;
}
Entity Person
#Data
#Entity
public class Person extends Persistent<Long> {
private String name;
private String height;
private String mass;
#JsonProperty(value = "hair_color")
private String hairColor;
#JsonProperty(value = "skin_color")
private String skinColor;
#JsonProperty(value = "eye_color")
private String eyeColor;
#JsonProperty(value = "birth_year")
private String birthYear;
private String gender;
#JsonDeserialize(converter = ApiURLToEntityConverter.class)
#JoinColumn(name = "planet_id", foreignKey = #javax.persistence.ForeignKey(name = "none"))
#OneToOne(optional = true)
private Planet homeworld;
#JsonDeserialize(converter = ApiURLToEntitiesConverter.class)
#ManyToMany
#JoinTable(
name = "film_person",
joinColumns = #JoinColumn(name = "film_fk", referencedColumnName = "id", nullable = true),
inverseJoinColumns = #JoinColumn(name = "person_fk", referencedColumnName = "id", nullable = true))
private List<Film> films;
#JsonDeserialize(converter = StringToLocalDateTimeConverter.class)
private LocalDateTime created;
#JsonDeserialize(converter = StringToLocalDateTimeConverter.class)
private LocalDateTime edited;
private String url;
}
I am trying to use the spring jpa method to saveAll
#Override
public List<T> insertAll(List<T> entities) {
for (Persistent entity : entities) {
Set<ConstraintViolation<Persistent>> violations = validator.validate(entity);
if (violations != null && !violations.isEmpty()) {
throw new ConstraintViolationException(violations);
}
}
return repository.saveAll(entities);
}
Converter Method
#Override
public List convert(List<String> s) {
if (s == null || s.isEmpty()) {
return null;
}
List objetos = new LinkedList();
for (String url : s) {
if (url.contains("people")) {
objetos.add(Util.getPerson(url));
}
if (url.contains("planets")) {
objetos.add(Util.getPlanet(url));
}
if (url.contains("starships")) {
objetos.add(Util.getStarship(url));
}
if (url.contains("vehicles")) {
objetos.add(Util.getVehicle(url));
}
if (url.contains("species")) {
objetos.add(Util.getSpecie(url));
}
}
return objetos;
}
}
Util method
public static Person getPerson(String characterApiUrl) {
if (characterApiUrl == null || characterApiUrl.isEmpty()) {
return null;
}
Person person = new Person();
person.setId(StringUtil.getIdEntity(characterApiUrl, "people/"));
return person;
}
The relationship table is being created but no populated

Spring JpaRepository using EntityGraph returns null instead of Optional

Calling this method:
#EntityGraph(attributePaths = "permissionGroups")
Optional<User> findOneWithPermissionGroupsByLogin(String login);
With non-exsisting user login returns null instead of Optional.of(null).
I would like to figure out what should I add in order to get an Optional resault?
more complete code:
Repository
public interface UserRepository extends JpaRepository<User, Long>
{
Optional<User> findOneByLogin(String login);
#EntityGraph(attributePaths = "permissionGroups")
Optional<User> findOneWithPermissionGroupsByLogin(String login);
}
User Entity
this is relevant user entity code
#Entity
#Table(name = "jhi_user")
#Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class User extends AbstractAuditingEntity implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
#SequenceGenerator(name = "sequenceGenerator")
private Long id;
#NotNull
#Pattern(regexp = Constants.LOGIN_REGEX)
#Size(min = 1, max = 50)
#Column(length = 50, unique = true, nullable = false)
private String login;
#JsonIgnore
#ManyToMany
#JoinTable(
name = "jhi_user_authority",
joinColumns = {#JoinColumn(name = "user_id", referencedColumnName = "id")},
inverseJoinColumns = {#JoinColumn(name = "authority_name", referencedColumnName = "name")})
#Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
#BatchSize(size = 20)
private Set<Authority> authorities = new HashSet<>();
#ManyToMany
#Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
#JoinTable(name = "euser_permission_group",
joinColumns = #JoinColumn(name="eusers_id", referencedColumnName="id"),
inverseJoinColumns = #JoinColumn(name="permission_groups_id", referencedColumnName="id"))
private Set<PermissionGroup> permissionGroups = new HashSet<>();
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getLogin() {
return login;
}
//Lowercase the login before saving it in database
public void setLogin(String login) {
this.login = login.toLowerCase(Locale.ENGLISH);
}
public Set<Authority> getAuthorities() {
return authorities;
}
#Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
User user = (User) o;
return login.equals(user.login);
}
#Override
public int hashCode() {
return login.hashCode();
}

Spring Data rest how to perform CRUD on #manytomany relation ,composite table with extra column

I am unable to perform CRUD via json POST from restful client Postman on Composite table having extra column .I am using Spring boot ,spring data rest and spring JPA.
I have 3 tables in data base
-user
-competency
-user_competency (join/composite table with extra column)
Here are my classes
User
#Entity
#Table(name = "\"user\"", schema = "public")
#JsonIdentityInfo(
generator = ObjectIdGenerators.IntSequenceGenerator.class,
property = "userId")
public class User implements java.io.Serializable {
private Long userId;
#Id #GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "user_id", unique = true, nullable = false)
public Long getUserId() {
return this.userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
private Set<UserCompetency> userCompetencies = new HashSet<UserCompetency>(0);
#OneToMany(fetch = FetchType.EAGER,cascade = {CascadeType.ALL}, mappedBy = "user")
public Set<UserCompetency> getUserCompetencies() {
return this.userCompetencies;
}
public void setUserCompetencies(Set<UserCompetency> userCompetencies) {
this.userCompetencies = userCompetencies;
}
}
Competency
#Entity
#Table(name = "competency", schema = "public")
#JsonIdentityInfo(
generator = ObjectIdGenerators.IntSequenceGenerator.class,
property = "competencyId")
public class Competency implements java.io.Serializable {
private Long competencyId;
private Set<UserCompetency> userCompetencies = new HashSet<UserCompetency>(0);
#Id #GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "competency_id", unique = true, nullable = false)
public Long getCompetencyId() {
return this.competencyId;
}
public void setCompetencyId(Long competencyId) {
this.competencyId = competencyId;
}
#OneToMany(fetch = FetchType.LAZY, mappedBy = "competency")
public Set<UserCompetency> getUserCompetencies() {
return this.userCompetencies;
}
public void setUserCompetencies(Set<UserCompetency> userCompetencies) {
this.userCompetencies = userCompetencies;
}
}
UserCompetency
#Entity
#Table(name = "user_competency", schema = "public")
#JsonIdentityInfo(
generator =ObjectIdGenerators.IntSequenceGenerator.class,
property = "id")
public class UserCompetency implements java.io.Serializable {
private UserCompetencyId id;
private Level level;
private User user;
private Competency competency;
#EmbeddedId
#AttributeOverrides({
#AttributeOverride(name = "competencyId", column = #Column(name = "competency_id", nullable = false)),
#AttributeOverride(name = "userId", column = #Column(name = "user_id", nullable = false)) })
public UserCompetencyId getId() {
return this.id;
}
public void setId(UserCompetencyId id) {
this.id = id;
}
#ManyToOne(fetch = FetchType.EAGER)
#JoinColumn(name = "level_id")
public Level getLevel() {
return this.level;
}
public void setLevel(Level level) {
this.level = level;
}
#ManyToOne(fetch = FetchType.EAGER)
#JoinColumn(name = "user_id", nullable = false, insertable = false, updatable = false)
public User getUser() {
return this.user;
}
public void setUser(User user) {
this.user = user;
}
#ManyToOne(fetch = FetchType.EAGER,cascade=CascadeType.ALL)
#JoinColumn(name = "competency_id", nullable = false, insertable = false, updatable = false)
public Competency getCompetency() {
return this.competency;
}
public void setCompetency(Competency competency) {
this.competency = competency;
}
}
UserCompetencyId
#Embeddable
public class UserCompetencyId implements java.io.Serializable {
private Long competencyId;
private Long userId;
public UserCompetencyId() {
}
public UserCompetencyId(Long competencyId, Long userId) {
this.competencyId = competencyId;
this.userId = userId;
}
#Column(name = "competency_id", nullable = false)
public Long getCompetencyId() {
return this.competencyId;
}
public void setCompetencyId(Long competencyId) {
this.competencyId = competencyId;
}
#Column(name = "user_id", nullable = false)
public Long getUserId() {
return this.userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof UserCompetencyId))
return false;
UserCompetencyId castOther = (UserCompetencyId) other;
return (this.getCompetencyId() == castOther.getCompetencyId()) && (this.getUserId() == castOther.getUserId());
}
}
Suppose i have already record in User and Competency tables and i want to assocaite both i am trying to post like this ,but it give me error of 405 Method Not Allowed.
help required ,what should be structure of json to be posted User will already exist and competency will might exist or new can be added and associated with existing user.
With this code I was able to post a new relation:
UserCompetency.class
#Entity
#Table(name = "user_competency")
#IdClass(UserCompetencyId.class)
public class UserCompetency implements java.io.Serializable {
#Id #ManyToOne
#JoinColumn(name = "competency_id", nullable = false, insertable = false, updatable = false)
private Competency competency;
#Id #ManyToOne
#JoinColumn(name = "user_id", nullable = false, insertable = false, updatable = false)
private User user;
UserCompetencyId.class
public class UserCompetencyId implements java.io.Serializable {
private Long competency;
private Long user;
public UserCompetencyId() {
}
public UserCompetencyId(Long competency, Long user) {
this.competency = competency;
this.user = user;
}
UserCompetencyRepository.class
public interface UserCompetencyRepository extends JpaRepository<UserCompetency, UserCompetencyId> {
}
POST http://localhost:8080/userCompetencies
{
"competency": "/competencies/2"
, "user": "/user/4"
}
Apparently there seems to be no "natural/easy" way to get what you want. But there is a promissing project for integrating embeddables by extending the serialization process: https://github.com/gregturn/embeddable-spring-data-rest
UserCompetencyIdJacksonModule, UserCompetencyIdSerializer, ..
Then you should be able PATCH (not POST) your JSON from above.

how to rectify this mapping exception( Use of #OneToMany or #ManyToMany targeting an unmapped class)

Hi I am getting some mapping exception please follow the below error
org.hibernate.AnnotationException: Use of #OneToMany or #ManyToMany targeting an unmapped class: com.cmr.daos.child.domain.Child.medications[com.cmr.daos.child.domain.Medications]
at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1185)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:710)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:645)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:65)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1716)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1423)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:720)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
... 62 more
My domain class:
public class Child extends AuditProperties implements java.io.Serializable {
#Expose private Long childId;
#Expose private String firstName;
#Expose private String lastName;
private Set<Allergies> allergies = new HashSet<Allergies>();
private Set<Medications> medications = new HashSet<Medications>();
#OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "child")
#JsonManagedReference
public Set<Medications> getMedications() {
return this.medications;
}
public void setMedications(Set<Medications> medications) {
this.medications = medications;
}
#OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "child")
#JsonManagedReference
public Set<Allergies> getAllergies() {
return this.allergies;
}
public void setAllergies(Set<Allergies> allergies) {
this.allergies = allergies;
}
#Id
#GeneratedValue(strategy = IDENTITY)
#Column(name = "CHILD_ID", unique = true, nullable = false)
public Long getChildId() {
return this.childId;
}
public void setChildId(Long childId) {
this.childId = childId;
}
#Column(name = "FIRST_NAME", nullable = false, length = 64)
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
#Column(name = "LAST_NAME", nullable = false, length = 64)
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
Here my mapped classs:
public class Medications extends AuditProperties implements java.io.Serializable{
#Expose private Long medicationId;
#Expose private String hasMedication;
#Expose private String medicationType;
#Expose private transient Child child;
#ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
#JoinColumn(name = "CHILD_ID")
#JsonBackReference
public Child getChild() {
return child;
}
public void setChild(Child child) {
this.child = child;
}
#Id
#GeneratedValue(strategy = IDENTITY)
#Column(name = "MEDICATION_ID", unique = true, nullable = false)
public Long getMedicationId() {
return medicationId;
}
public void setMedicationId(Long medicationId) {
this.medicationId = medicationId;
}
#Column(name = "HAS_MEDICATION", nullable = false, length = 3)
public String getHasMedication() {
return hasMedication;
}
public void setHasMedication(String hasMedication) {
this.hasMedication = hasMedication;
}
#Column(name = "MEDICATION_TYPE", length = 64)
public String getMedicationType() {
return medicationType;
}
public void setMedicationType(String medicationType) {
this.medicationType = medicationType;
}
}
Here another mapped class:
#Entity
#Table(name = "ALLERGIES")
public class Allergies extends AuditProperties implements java.io.Serializable {
#Expose private Long allergyId;
#Expose private String hasAllergies;
#Expose private String allerigyType;
#Expose private transient Child child;
#ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
#JoinColumn(name = "CHILD_ID")
#JsonBackReference
public Child getChild() {
return child;
}
public void setChild(Child child) {
this.child = child;
}
#Id
#GeneratedValue(strategy = IDENTITY)
#Column(name = "ALLERGY_ID", unique = true, nullable = false)
public Long getAllergyId() {
return allergyId;
}
public void setAllergyId(Long allergyId) {
this.allergyId = allergyId;
}
#Column(name = "HAS_ALLERGIES", length = 3)
public String getHasAllergies() {
return hasAllergies;
}
public void setHasAllergies(String hasAllergies) {
this.hasAllergies = hasAllergies;
}
#Column(name = "ALLERIGY_TYPE", length = 20)
public String getAllerigyType() {
return allerigyType;
}
public void setAllerigyType(String allerigyType) {
this.allerigyType = allerigyType;
}
}
Here i mentioned one child class, allergy class and medication class.Here i mapped child object to both the classes(allergy,medications) then i will get this exception.please help me abot this exception
As the exception says:
Use of #OneToMany or #ManyToMany targeting an unmapped class:
com.cmr.daos.child.domain.Child.medications[com.cmr.daos.child.domain.Medications]
Hibernate is trying to find the entity Medications that represents the property medications in your Child class.
Looking at the etities everything looks good, so I assume you missed to place #Entity for Medications class or you missed to mention about this entity in hibernate.cfg.xml file.

Resources