jpa

Show ads of people you follow Spring JPA

谁说胖子不能爱 提交于 2021-01-29 06:47:07
问题 I have a User, an Ad, and a table Follows that show who follows who. What I need to do is I need to implement a button that on clicked (and being loged in) regsiters that follow on the Follows table, and them you need to be able to show just de Ads ofthe people you follow (Currently there's only a view of ALL the ads, and now I need to make one that just shows the one that have been posted by the users I follow) Any ideas of how can I make that possible? AdRepository: @Repository public

JPA Hibernate cascade type for child of child

会有一股神秘感。 提交于 2021-01-29 06:44:42
问题 I was looking for documentation or answer how will the cascade work for child of child , example : public class Parent{ @OneToMany(fetch = FetchType.EAGER,mappedBy = "parent",cascade = CascadeType.ALL) private List<Child> child; } public class Child{ @OneToMany(mappedBy="child") private List<AnotherChild> anohterChild; } @ManyToOne private Parent parent; } now the question, will the cascade operation applied on "Child" from parent class apply to "AnotherChild" ? in other words if I persist

How can I configure JPA for a postgres database schema?

只愿长相守 提交于 2021-01-29 06:34:18
问题 I have an existing postgres database with the database "testdb" and the database schema testdbschema". If I use the default persistence.xml configuration of RESOURCE_LOCAL the following property is working: <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://server:port/testdb?currentSchema=testdbschema" /> I want to configure my database connection within my web.xml as a data-source. Everything is working well, except the configuration of the database schema. Here is my web

Hibernate MappingException: Foreign key must have same number of columns as the referenced primary key

大憨熊 提交于 2021-01-29 05:36:04
问题 I have this entity, called FatRabbitCarrot: @Entity public class FatRabbitCarrot { private Long id; private FatRabbit fatRabbit; private Carrot carrot; @Id @Column(name = "id", nullable = false) @GeneratedValue(strategy = GenerationType.IDENTITY) public Long getId() { return id; } public void setId(Long id) { this.id = id; } @ManyToOne @JoinColumn(name = "fatRabbit_id", foreignKey = @ForeignKey(name = "FK_FatRabbitCarrot_fatRabbit")) public FatRabbit getFatRabbit() { return fatRabbit; }

JpaRepository merge() method

£可爱£侵袭症+ 提交于 2021-01-29 05:30:29
问题 I'm rewriting a big project with SpringBoot 2.2.6 and I'm run into a problem. In the old project (pure ejb ) when a complex entity is updated, the code build entity from DTO's as follows: public Entity dtoToEntity(DTO dto) { Entity entity = new Entity(); entity.setId(dto.getID()); // ecc... // ecc... entity.setSubEntity(dto.getSubEntity() != null ? new SubEntity(dto.getSubEntity().getId() : null); // and so on } The important section is that related to subentity! After made a mapping like

Not able to connect to MySQL - Glassfish and Hibernate

ぃ、小莉子 提交于 2021-01-29 02:50:40
问题 I have the below persistence file - <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="unit" > <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> <property name=

Not able to connect to MySQL - Glassfish and Hibernate

早过忘川 提交于 2021-01-29 02:47:26
问题 I have the below persistence file - <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="unit" > <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> <property name=

Use Generic in JPA @OneToMany

邮差的信 提交于 2021-01-29 00:40:36
问题 I have a class "Branch". Either classes "Dictionary" and "Link" which I want to use as < T> here. @Entity public class Branch<T> { ... @OneToMany(mappedBy = "branch", orphanRemoval = true, cascade = CascadeType.ALL) private List<T> entities = new ArrayList<>(); } It throws a Runtime Exception: org.hibernate.AnnotationException: Property by.ipps.accounting.model.Branch.branches has an unbound type and no explicit target entity. Resolve this Generic usage issue or set an explicit target

JEE7 @Transactional annotation not always fires

橙三吉。 提交于 2021-01-28 23:40:31
问题 For several days I'm trying to manage with JPA transactions after moving to WildFly 8 server and JEE7 and I cannot understand why in some cases @Transactional (javax.transaction.Transactional) annotation doesn't intercept method annotated with it. I cannot see any rule why sometimes it works and sometimes not. Example of my not working code: import javax.inject.Inject; import javax.inject.Named; import javax.persistence.EntityManager; import javax.faces.view.ViewScoped; import com.i4u.app

CrudRepository.save() appears to cascade

跟風遠走 提交于 2021-01-28 22:55:30
问题 Entity Survey: @Entity @Table(name = "Survey") public class Survey implements Serializable { private Long id; private String name; private String address; private List<Question> questions; @Id @Column(name = "id") public Long getId() { return id; } @Column(name = "name") public String getName() { return name; } @Column(name = "address") public String getAddress() { return address; } @OneToMany(fetch = FetchType.LAZY, mappedBy = "survey") public List<Question> getQuestions() { return questions