Spring-data-jpa same table name on two datasources "Duplicate entity name" - spring-data-jpa

I'm using spring-data-jpa with two datasources,
but my two schema elettroforesi and capillare both have a table ANALISI
and Eclipse show me the following error:
"Duplicate entity name "Analisi" found in the persistence unit. Entity names must be unique."
the Config are the following:
#Configuration
#PropertySource({ "classpath:persistence-multiple-db.properties" })
#EnableTransactionManagement
#EnableJpaRepositories(
basePackages = "com.interlabsrl.elfolab.persistence.multiple.repository.elettroforesi",
entityManagerFactoryRef = "elettroforesiEntityManager",
transactionManagerRef = "elettroforesiTransactionManager")
#ComponentScan(basePackages={"com.interlabsrl.elfolab.controller",
"com.interlabsrl.elfolab.persistence.multiple.service",
"com.interlabsrl.elfolab.persistence.multiple.cache"})
public class ElettroforesiConfig {
#Autowired
private Environment env;
public ElettroforesiConfig() {
super();
}
#Bean
#Primary
public LocalContainerEntityManagerFactoryBean elettroforesiEntityManager() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setPersistenceUnitName("elettroforesi");
em.setDataSource(elettroforesiDataSource());
em.setPackagesToScan(new String[] { "com.interlabsrl.elfolab.persistence.multiple.model.elettroforesi" });
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
final HashMap<String, Object> properties = new HashMap<String, Object>();
properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
properties.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
properties.put("hibernate.show_sql", env.getProperty("hibernate.show_sql"));
properties.put("hibernate.format_sql", env.getProperty("hibernate.format_sql"));
properties.put("hibernate.jdbc.batch_size", env.getProperty("hibernate.jdbc.batch_size"));
em.setJpaPropertyMap(properties);
return em;
}
#Bean
#Primary
public DataSource elettroforesiDataSource() {
final DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName")));
dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("elettroforesi.jdbc.url")));
dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("elettroforesi.jdbc.user")));
dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("elettroforesi.jdbc.pass")));
return dataSource;
}
#Bean
#Primary
public PlatformTransactionManager elettroforesiTransactionManager() {
final JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(elettroforesiEntityManager().getObject());
return transactionManager;
}
}
and
#Configuration
#PropertySource({ "classpath:persistence-multiple-db.properties" })
#EnableTransactionManagement
#EnableJpaRepositories(
basePackages = "com.interlabsrl.elfolab.persistence.multiple.repository.capillare",
entityManagerFactoryRef = "capillareEntityManager",
transactionManagerRef = "capillareTransactionManager")
#ComponentScan(basePackages={"com.interlabsrl.elfolab.controller",
// , "com.interlabsrl.elfolab.persistence.multiple.service"
// "com.interlabsrl.elfolab.persistence.multiple.cache"
})
public class CapillareConfig {
#Autowired
private Environment env;
public CapillareConfig() {
super();
}
#Bean
public LocalContainerEntityManagerFactoryBean capillareEntityManager() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setPersistenceUnitName("capillare");
em.setDataSource(capillareDataSource());
em.setPackagesToScan(new String[] { "com.interlabsrl.elfolab.persistence.multiple.model.capillare" });
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
final HashMap<String, Object> properties = new HashMap<String, Object>();
properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
properties.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
properties.put("hibernate.show_sql", env.getProperty("hibernate.show_sql"));
properties.put("hibernate.format_sql", env.getProperty("hibernate.format_sql"));
properties.put("hibernate.jdbc.batch_size", env.getProperty("hibernate.jdbc.batch_size"));
em.setJpaPropertyMap(properties);
return em;
}
#Bean
public DataSource capillareDataSource() {
final DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName")));
dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("capillare.jdbc.url")));
dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("capillare.jdbc.user")));
dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("capillare.jdbc.pass")));
return dataSource;
}
#Bean
public PlatformTransactionManager capillareTransactionManager() {
final JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(capillareEntityManager().getObject());
return transactionManager;
}
}
while the entities:
package com.interlabsrl.elfolab.persistence.multiple.model.elettroforesi;
#Entity
#NamedQueries({
#NamedQuery(name = "Analisi.findAll", query = "SELECT a FROM Analisi a")})
#Table(schema="elettroforesi")
public class Analisi implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Basic(optional = false)
#Column(name = "ID_ANALISI", nullable = false)
private Integer idAnalisi;
#Basic(optional = false)
#NotNull
#Column(nullable = false)
private short tracciato;
#Size(max = 30)
#Column(length = 30)
private String campione;
#Size(max = 40)
#Column(length = 40)
private String reparto;
#Column(name = "TOTALE_PROTEINE", precision = 12)
private Float totaleProteine;
#Column(name = "RAPP_AG", precision = 12)
private Float rappAg;
#Column(name = "DATA_MODIFICA")
#Temporal(TemporalType.TIMESTAMP)
private Date dataModifica;
#Column(name = "DATA_VALIDAZIONE")
#Temporal(TemporalType.TIMESTAMP)
private Date dataValidazione;
#Column(name = "DATA_CANCELLAZIONE")
#Temporal(TemporalType.TIMESTAMP)
private Date dataCancellazione;
#OneToMany(mappedBy = "idAnalisiLink")
private Collection<Analisi> analisiCollection;
#JoinColumn(name = "ID_ANALISI_LINK", referencedColumnName = "ID_ANALISI")
#ManyToOne
private Analisi idAnalisiLink;
#JoinColumn(name = "ID_ANALISI_IFE", referencedColumnName = "ID_ANALISI_IFE")
#ManyToOne
private AnalisiIfe idAnalisiIfe;
#JoinColumn(name = "ID_ANALISI_NOTA", referencedColumnName = "ID_ANALISI_NOTA")
#ManyToOne
private AnalisiNota idAnalisiNota;
#JoinColumn(name = "ID_PATOLOGICO", referencedColumnName = "ID_PATOLOGICO")
#ManyToOne
private Patologico idPatologico;
#JoinColumn(name = "ID_PAZIENTE", referencedColumnName = "ID_PAZIENTE", nullable = false)
#ManyToOne(optional = false)
private Paziente idPaziente;
#JoinColumn(name = "ID_SESSIONE", referencedColumnName = "ID_SESSIONE", nullable = false)
#ManyToOne(optional = false)
private Sessione idSessione;
#JoinColumn(name = "ID_TIPO_VALIDAZIONE", referencedColumnName = "ID_TIPO_VALIDAZIONE", nullable = false)
#ManyToOne(optional = false)
private TipoValidazione idTipoValidazione;
#JoinColumn(name = "ID_UTENTE_CANCELLAZIONE", referencedColumnName = "ID_UTENTE")
#ManyToOne(fetch=FetchType.LAZY)
private Utente idUtenteCancellazione;
#JoinColumn(name = "ID_UTENTE_MODIFICA", referencedColumnName = "ID_UTENTE")
#ManyToOne(fetch=FetchType.LAZY)
private Utente idUtenteModifica;
#JoinColumn(name = "ID_UTENTE_VALIDAZIONE", referencedColumnName = "ID_UTENTE")
#ManyToOne(fetch=FetchType.LAZY)
private Utente idUtenteValidazione;
#OneToMany(mappedBy = "idAnalisi", fetch=FetchType.LAZY)
private Collection<AnalisiFrazione> analisiFrazioneCollection;
#OneToMany(mappedBy = "idAnalisi", fetch=FetchType.LAZY)
private Collection<AnalisiAntisiero> analisiAntisieroCollection;
#OneToMany(mappedBy = "idAnalisi", fetch=FetchType.LAZY)
private Collection<AnalisiSmc> analisiSmcCollection;
#OneToMany(mappedBy = "idAnalisi", fetch=FetchType.LAZY)
private Collection<AnalisiCampoFree> analisiCampoFreeCollection;
#OneToMany(mappedBy = "idAnalisi", fetch=FetchType.LAZY)
private Collection<AnalisiDati> analisiDatiCollection;
#OneToMany(mappedBy = "idAnalisi")
private Collection<AnalisiNefelometrico> analisiNefelometricoCollection;
...
}
and
package com.interlabsrl.elfolab.persistence.multiple.model.capillare;
...
#Entity
#NamedQueries({
#NamedQuery(name = "Analisi.findAll", query = "SELECT a FROM Analisi a")})
#Table(schema="capillare")
public class Analisi implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Basic(optional = false)
#Column(nullable = false)
private Long id;
#Column(name = "id_macchina")
private Integer idMacchina;
#Column(name = "id_metodiche")
private Integer idMetodiche;
#Column(name = "numero_sessione")
private Integer numeroSessione;
#Temporal(TemporalType.TIMESTAMP)
private Date dataora;
#Temporal(TemporalType.DATE)
private Date data;
#Size(max = 20)
#Column(name = "barcode_provetta", length = 20)
private String barcodeProvetta;
#Size(max = 20)
#Column(name = "barcode_rack", length = 20)
private String barcodeRack;
#Size(max = 100)
#Column(name = "dati_lettura", length = 100)
private String datiLettura;
private Short acquisito;
...
}

Your entities are both named Analisi, try to change the second one to Capillare.
You named the table Capillare, but the class is named Analisi

Related

How to add new records to a field with #OneToOne in spring Data?

I am making a jsf + spring application.
The database contains a table of games and it is displayed on one of the pages of the site.
Each game has a genre list and development status. These fields are annotated with #OneToMany and #OneToOne respectively and are also tables in the database.
But here's the question: How do I add new games now? How do I initialize these fields? Because the only way I see is to create a new genre for a new game every time. That is, even if game A and games B are of the same genre, then I have to create two different unique genres, not one.
And how to initialize these fields from JSF?
For example from the <p: selectOneMenu> tag
game.java
#Setter
#Getter
#NoArgsConstructor
#AllArgsConstructor
#Entity
#Table(name = "game")
public class Game
{
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
#Column(name = "name")
private String name;
#Column(name = "budget")
private String budget;
#Column(name = "profit")
private String profit;
#Column(name = "number")
private String number;
#OneToOne(optional = false, cascade = CascadeType.REFRESH)
#JoinColumn(name = "platform")
private Platform platform;
#OneToOne(optional = false, cascade = CascadeType.REFRESH)
#JoinColumn(name = "status")
private Status status;
#Column(name = "start")
private Date start;
#Column(name = "end")
private Date end;
#OneToMany(fetch = FetchType.EAGER)
#JoinTable(name = "game_genre",
joinColumns = #JoinColumn(name= "game_id"),
inverseJoinColumns = #JoinColumn(name= "genre_id"))
private List<Genre> listGenre;
public void update(Game new_game)
{
this.name = new_game.name;
this.budget = new_game.budget;
this.profit = new_game.profit;
this.number = new_game.number;
this.platform = new_game.platform;
this.status = new_game.status;
this.start = new_game.start;
this.end = new_game.end;
}
}
development status
#Setter
#Getter
#NoArgsConstructor
#AllArgsConstructor
#Entity
#Table(name = "status")
public class Status implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#Column(name = "Название")
private String Name;
#Column(name = "Описание")
private String description;
public void update(Status new_game)
{
this.description = new_game.description;
this.Name = new_game.Name;
}
}
genre:
#Setter
#Getter
#NoArgsConstructor
#AllArgsConstructor
#Entity
#Table(name = "genre")
public class Genre implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#Column(name = "name")
private String name;
#Column(name = "description")
private String description;
public void update(Genre new_game)
{
this.name = new_game.name;
this.description = new_game.description;
}
}
Bean
#Component(value = "listgames")
#SessionScope
public class GamesView {
#Autowired
private GamesService gamesService;
private Map<Long, Boolean> checked = new HashMap<Long, Boolean>();
private List<Game> All_games = new ArrayList<Game>();
private Game newGame=new Game();
public Game getNewGame() {
return newGame;
}
public void setNewGame(Game newGame) {
this.newGame = newGame;
}
public void onRowEdit(RowEditEvent event) {
Game new_game=(Game)event.getObject();
All_games.get(new_game.getId()-1).update(new_game);
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "INFO", "X/Y edit successful!");
FacesContext.getCurrentInstance().addMessage(null, msg);
int i=0;
i++;
}
public void createNew() {
gamesService.addBank(newGame);
newGame = new Game();
}
public List<Game> getAll_games() {
return gamesService.getAll();
}
public void setAll_games(List<Game> all_games) {
All_games = all_games;
}
}

Why List(#OneToMany) with JPA in Entity seen PersistentBag

I have two entities as follows Personel.java and PersonelEgitimDurum.java
List personelEgitimDurumList is PersistentBag in Personel as seen follows;
[enter image description here][1]
[1]: https://i.stack.imgur.com/Q3IC2.png
Personel.java as follows;
#Entity
#Table(name="personel")
public class Personel extends BaseEntity {
#OneToOne(cascade = CascadeType.ALL)
#JoinColumn(name="kisi_id")
private Kisi kisi;
#Column(name="personel_tipi",length = 2,nullable = false)
private int personelTipi;
#Column(name="sicil_no",length = 100,nullable = false)
private String sicilNo;
#OneToMany(fetch = FetchType.EAGER, mappedBy = "personel", cascade =CascadeType.ALL,orphanRemoval = true)
private List<PersonelEgitimDurum> personelEgitimDurumList= new ArrayList<PersonelEgitimDurum>();
#Column(name="khk_onay",length = 1)
private int khkOnay;
}
PersonelEgitimDurum.java as follows;
#Entity
#Table(name = "personel_egitim_durum", indexes = {#Index(name = "index_personel_egitim_durum", columnList = "id")})
public class PersonelEgitimDurum extends BaseEntity {
#ManyToOne(cascade=CascadeType.PERSIST,fetch=FetchType.EAGER)
#JoinColumn(name="personel_id",nullable = false, updatable = true)
private Personel personel;
#Column(name = "ogrenim_durumu")
private String ogrenimDurumu;
#Column(name = "okul_id", length = 3)
private Long okulId;
#Column(name = "universite_bolum_id", length = 4)
private Long universiteBolumId;
#Column(name = "mezuniyet_tarihi")
private Date mezuniyetTarihi;
#Column(name = "aciklama", length = 500)
private String aciklama;
}
PersonelServiceImpl.java as follows;
#Service
#Transactional
public class PersonelServiceImpl implements PersonelService {
#Override
public PersonelDTO findPersonelByKimlikNo(String kimlikNo) {
Kisi kisi=kisiDAO.findKisiByKimlikNo(kimlikNo);
Personel personel=personelDao.findPersonelByKisi(kisi);
PersonelDTO personelDTO=mapper.toDto(personel);
return personelDTO;
}
}
Problem is that personel from findPersonelByKimlikNo in PersonelServiceImpl include that personelEgitimDurumList is PersistentBag as image. So mapStruct does not convert entity to dto.
Error log follows;
java.lang.StackOverflowError: null
at org.hibernate.collection.internal.PersistentBag.size(PersistentBag.java:261) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
at org.kktcmeb.personel.kktcmebpersonel.mapper.PersonelMapperImpl.personelEgitimDurumListToPersonelEgitimDurumDTOList(PersonelMapperImpl.java:159) ~[classes/:na]
at org.kktcmeb.personel.kktcmebpersonel.mapper.PersonelMapperImpl.toDto(PersonelMapperImpl.java:53) ~[classes/:na]
at org.kktcmeb.personel.kktcmebpersonel.mapper.PersonelMapperImpl.personelEgitimDurumToPersonelEgitimDurumDTO(PersonelMapperImpl.java:144) ~[classes/:na]
at org.kktcmeb.personel.kktcmebpersonel.mapper.PersonelMapperImpl.personelEgitimDurumListToPersonelEgitimDurumDTOList(PersonelMapperImpl.java:161) ~[classes/:na]
at org.kktcmeb.personel.kktcmebpersonel.mapper.PersonelMapperImpl.toDto(PersonelMapperImpl.java:53) ~[classes/:na]
Anyone have idea about this situation? Please help
#Entity
#Table(name="personel")
**#JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")**
public class Personel extends BaseEntity {
#OneToOne(cascade = CascadeType.ALL)
#JoinColumn(name="kisi_id")
private Kisi kisi;
#Column(name="personel_tipi",length = 2,nullable = false)
private int personelTipi;
#Column(name="sicil_no",length = 100,nullable = false)
private String sicilNo;
#OneToMany(fetch = FetchType.EAGER, mappedBy = "personel", cascade =CascadeType.ALL,orphanRemoval = true)
private List<PersonelEgitimDurum> personelEgitimDurumList= new ArrayList<PersonelEgitimDurum>();
#Column(name="khk_onay",length = 1)
private int khkOnay;
}
ADD to head of entities->#JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
#Entity
#Table(name = "personel_egitim_durum", indexes = {#Index(name = "index_personel_egitim_durum", columnList = "id")})
#JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
public class PersonelEgitimDurum extends BaseEntity {
#ManyToOne(cascade=CascadeType.PERSIST,fetch=FetchType.EAGER)
#JoinColumn(name="personel_id",nullable = false, updatable = true)
private Personel personel;
#Column(name = "ogrenim_durumu")
private String ogrenimDurumu;
#Column(name = "okul_id", length = 3)
private Long okulId;
#Column(name = "universite_bolum_id", length = 4)
private Long universiteBolumId;
#Column(name = "mezuniyet_tarihi")
private Date mezuniyetTarihi;
#Column(name = "aciklama", length = 500)
private String aciklama;
}

Spring/JPA: Multiple Relations between same Entities without circular references

Good morning everyone. Im trying to build an spring application that has two ManyToMany relations between the same entities: A team has several members and leaders.
First entity:
#Entity
#Table(name = "team")
#Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Team implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
#SequenceGenerator(name = "sequenceGenerator")
private Long id;
#ManyToMany(fetch = FetchType.LAZY)
#JoinTable(name = "team2member", joinColumns = #JoinColumn(name = "team_id", referencedColumnName = "id"), inverseJoinColumns = #JoinColumn(name = "user_id", referencedColumnName = "id"))
private Set<User> members = new HashSet<User>();
#ManyToMany(fetch = FetchType.LAZY)
#JoinTable(name = "team2leader", joinColumns = #JoinColumn(name = "team_id", referencedColumnName = "id"), inverseJoinColumns = #JoinColumn(name = "user_id", referencedColumnName = "id"))
private Set<User> leaders = new HashSet<User>();
// Members (ManyToMany)
public Set<User> getMembers() {
return members;
}
public void setMembers(Set<User> members) {
this.members = members;
}
public void addMember(User member) {
this.members.add(member);
}
public void removeMember(User member) {
this.members.remove(member);
}
// Leaders (ManyToMany)
public Set<User> getLeaders() {
return leaders;
}
public void setLeaders(Set<User> leaders) {
this.leaders = leaders;
}
public void addLeader(User leader) {
this.leaders.add(leader);
}
public void removeLeader(User leader) {
this.members.remove(leader);
}
}
Second entity:
#Entity
#Table(name = "user")
#Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class User implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
#SequenceGenerator(name = "sequenceGenerator")
private Long id;
#ManyToMany(fetch = FetchType.LAZY)
#JoinTable(name = "team2member", joinColumns = #JoinColumn(name = "user_id", referencedColumnName = "id"), inverseJoinColumns = #JoinColumn(name = "team_id", referencedColumnName = "id"))
private Set<Team> teams = new HashSet<Team>();
#ManyToMany(fetch = FetchType.LAZY)
#JoinTable(name = "team2leader", joinColumns = #JoinColumn(name = "user_id", referencedColumnName = "id"), inverseJoinColumns = #JoinColumn(name = "team_id", referencedColumnName = "id"))
private Set<Team> leadedTeams = new HashSet<Team>();
// Teams (ManyToMany)
public Set<Team> getTeams() {
return teams;
}
public void setTeams(Set<Team> teams) {
this.teams = teams;
}
public void addTeam(Team team) {
this.teams.add(team);
}
public void removeTeam(Team team) {
this.teams.remove(team);
}
// LeadedTeams (ManyToMany)
public Set<Team> getLeadedTeams() {
return leadedTeams;
}
public void setLeadedTeams(Set<Team> leadedTeams) {
this.leadedTeams = leadedTeams;
}
public void addLeadedTeam(Team leadedTeam) {
this.leadedTeams.add(leadedTeam);
}
public void removeLeadedTeam(Team leadedTeam) {
this.leadedTeams.remove(leadedTeam);
}
}
My question: Cause im facing a stackoverflow issue im wondering if it is possible this way. Or maybe there is a better solution for this problem?
StackTrace (shorted):
2018-03-27 01:19:08.635 DEBUG 12656 --- [ XNIO-2 task-12] n.s.aop.logging.LoggingAspect : Exit: net.schwungkraft.service.DocumentService.findAllForOrderHeader() with result = Page 1 of 0 containing UNKNOWN instances
2018-03-27 01:19:08.636 DEBUG 12656 --- [ XNIO-2 task-12] n.s.aop.logging.LoggingAspect : Exit: net.schwungkraft.web.rest.OrderHeaderResource.getDocumentsForOrderHeader() with result = <200 OK,[],{X-Total-Count=[0], Link=[</api/order-headers/%7Bid%7D/documents?page=0&size=20>; rel="last",</api/order-headers/%7Bid%7D/documents?page=0&size=20>; rel="first"]}>
2018-03-27 01:19:08.645 DEBUG 12656 --- [ XNIO-2 task-13] n.s.aop.logging.LoggingAspect : Exit: net.schwungkraft.service.OrderHeaderService.findOneForCurrentUser() with result = OrderHeader{id=3102, orderScopeType='BEWERBUNG', dateStart='null', dateEnd='null', duration=null, classType='null', estimatedNoOfApplicants=null, isTaxLiable='false', amountWithoutTaxes=null, taxesPercent=null, taxesAmount=null, amountWithTaxes=null, extraGrantApplicants=null, extraGrantOthers=null, reminderDate='null', rating='null', ratingText='null', category='null', freeText='null', histComissionRateTitle=null, histPaymentTermDescription='3D', histPaymentTimeLimit=null, histPaymentTermTimeLimitForDiscount=null, histPaymentTermDiscount=null, histContactName='test', histContactStreet='null', histContactPostCode=null, histContactCity='null', histContactCountry='null', histContactContactPerson='null', histContactEmail='null', histContactPhoneNumber='null'}
2018-03-27 01:19:08.645 DEBUG 12656 --- [ XNIO-2 task-13] n.s.aop.logging.LoggingAspect : Exit: net.schwungkraft.web.rest.OrderHeaderResource.getOrderHeader() with result = <200 OK,OrderHeader{id=3102, orderScopeType='BEWERBUNG', dateStart='null', dateEnd='null', duration=null, classType='null', estimatedNoOfApplicants=null, isTaxLiable='false', amountWithoutTaxes=null, taxesPercent=null, taxesAmount=null, amountWithTaxes=null, extraGrantApplicants=null, extraGrantOthers=null, reminderDate='null', rating='null', ratingText='null', category='null', freeText='null', histComissionRateTitle=null, histPaymentTermDescription='3D', histPaymentTimeLimit=null, histPaymentTermTimeLimitForDiscount=null, histPaymentTermDiscount=null, histContactName='test', histContactStreet='null', histContactPostCode=null, histContactCity='null', histContactCountry='null', histContactContactPerson='null', histContactEmail='null', histContactPhoneNumber='null'},{}>
2018-03-27 01:19:09.162 ERROR 12656 --- [raft-Executor-2] n.s.c.audit.AsyncEntityAuditEventWriter : Exception while getting entity ID and content {}
com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: org.hibernate.collection.internal.PersistentSet[1]->net.schwungkraft.domain.User["leadedTeams"]->org.hibernate.collection.internal.PersistentSet[0]->net.schwungkraft.domain.Team["members"]->org.hibernate.collection.internal.PersistentSet[1]->net.schwungkraft.domain.User["leadedTeams"]->org.hibernate.collection.internal.PersistentSet[0]->net.schwungkraft.domain.Team["members"]->org.hibernate.collection.internal.PersistentSet[1]->net.schwungkraft.domain.User["leadedTeams"]->org.hibernate.collection.internal.PersistentSet[0]->net.schwungkraft.domain.Team["members"]->org.hibernate.collection.internal.PersistentSet[1]->net.schwungkraft.domain.User["leadedTeams"]->org.hibernate.collection.internal.PersistentSet[0]->net.schwungkraft.domain.Team["members"])
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:705)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155)
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:149)

Jpa Auditing dont save data in table auditing

I have to implementes Auditing in my aplication.. i inserting this data correctly
but i want to save all atributter from my Entity ,
Exemple, name, epigrafe, .. and olthers.
I implemented the mothod but dosent work, just dont save the atributte..
lets see..
#Entity
#EntityListeners(AuditingEntityListener.class)
#Table(name = "logradouros_historico", schema = "aud")
public class LogradourosHistorico {
#Id
#GeneratedValue
private Long id;
#ManyToOne(cascade = CascadeType.ALL)
#JoinColumn(name = "id_logradouro")
private Logradouros logradouro;
#CreatedBy
private String modificadoPor;
#CreatedDate
#Temporal(TemporalType.TIMESTAMP)
private Date modifiedDate = new Date();
#Enumerated(EnumType.STRING)
private Acoes acao;
#Column(name = "nome")
private String nome; //nome do logradouro
public LogradourosHistorico() {
super();
}
public LogradourosHistorico(Logradouros logradouro, String modificadoPor,
Acoes acao) {
super();
this.logradouro = logradouro;
this.modificadoPor = modificadoPor;
this.acao = acao;
}
//getters and setters
my class entityListner
public class LogradourosEntityListener {
#PostPersist
public void prePersist(Logradouros target) {
perform(target, Acoes.INSERTED);
}
#PreUpdate
public void preUpdate(Logradouros target) {
perform(target, Acoes.UPDATED);
}
#PreRemove
public void preRemove(Logradouros target) {
perform(target, Acoes.DELETED);
}
#Transactional()
private void perform(Logradouros target, Acoes acao) {
target.getNome();
EntityManager entityManager = BeanUtil.getBean(EntityManager.class);
entityManager.persist(new LogradourosHistorico(target, acao));
}
}
my class Logradouros
#Entity
#EntityListeners(LogradourosEntityListener.class)
#Table(name = "logradouros", schema = "glb", uniqueConstraints= #UniqueConstraint(columnNames={"id_entidade", "idLogradouro"}))
public class Logradouros extends Auditable<String> implements Serializable {
private static final long serialVersionUID = 3703309412387185484L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int idLogradouro;
#Column(name = "cep_geral")
private String cepGeral;
#Column(name = "epigrafe")
private String epigrafe;
#NotNull
#Column(name = "nome")
private String nome;
#Column(name = "nome_exibicao")
private String nomeExibicao;
#JoinColumn(name = "id_entidade")
#ManyToOne(/*cascade = CascadeType.ALL*/)
private Entidades entidade;
#NotNull
#JoinColumn(name = "id_municipio")
#ManyToOne(/*cascade = CascadeType.ALL*/)
private Municipios municipio;
// gettrs and settrs
so what i did wrong because i cant get the nome of entity Logradouros

Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property customer invoice

I am new to spring based project,
I have the requirement to create the entity relationship mapping between orders and invoices with OneToMany, and tried below mappings, but ending up with mapping error,
Could you please point me out to fix this issue.
#Entity
#Table(name="Customers")
public class Customers implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GenericGenerator(name = "generator", strategy = "increment")
#GeneratedValue(generator = "generator")
#Column(name = "CustomerId", nullable = false)
private Long CustomerId;
#OneToMany(cascade=CascadeType.ALL, mappedBy="Customers")
private Set<Orders> Orders = new HashSet<Orders>();
}
#Entity
#Table(name="Orders")
public class Orders implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GenericGenerator(name = "generator", strategy = "increment")
#GeneratedValue(generator = "generator")
#Column(name = "orderId", nullable = false)
private Long orderId;
#JoinColumn(name="CustomerId")
#ManyToOne
private Customers customers;
#OneToOne (optional=false,cascade=CascadeType.ALL, mappedBy="orders",targetEntity=Invoices.class)
private Invoices invoices;
}
#Entity
#Table(name="Invoices")
public class Invoices implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GenericGenerator(name = "generator", strategy = "increment")
#GeneratedValue(generator = "generator")
#Column(name = "invoiceId", nullable = false)
private Long invoiceId;
#OneToOne(optional=false,cascade=CascadeType.ALL, mappedBy="invoices",targetEntity=Orders.class)
private Orders orders;
}
Error message:
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.mycompany.myproject.persist.entity.Orders.Customers in com.mycompany.myproject.persist.entity.Customers.Orders
Probably because Orders has a property 'customers' and not 'Customers' (as specified by the 'mappedBy' attribute).
You should tidy up your class names and fields as below:
#Entity
#Table(name="Customers")
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GenericGenerator(name = "generator", strategy = "increment")
#GeneratedValue(generator = "generator")
#Column(name = "CustomerId", nullable = false)
private Long customerId;
#OneToMany(cascade=CascadeType.ALL, mappedBy="customer")
private Set<Order> orders = new HashSet<Order>();
}
#Entity
#Table(name="Orders")
public class Order implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GenericGenerator(name = "generator", strategy = "increment")
#GeneratedValue(generator = "generator")
#Column(name = "orderId", nullable = false)
private Long orderId;
#ManyToOne
#JoinColumn(name="CustomerId")
private Customer customer;
#OneToOne(optional=false, cascade=CascadeType.ALL, mappedBy="order")
private Invoice invoice;
}
#Entity
#Table(name="Invoices")
public class Invoice implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GenericGenerator(name = "generator", strategy = "increment")
#GeneratedValue(generator = "generator")
#Column(name = "invoiceId", nullable = false)
private Long invoiceId;
#OneToOne(optional=false,cascade=CascadeType.ALL)
#JoinColumn(name = "InvoiceId")
private Order order;
}