Help with a composite sleep pattern

So I'm stuck, I am creating a gwt web application, I will use the tree structure (gwt Tree and TreeItems) to show a list of folders (Folder class) and files (FileLocation class), the folder and file class will implement a hierarchy interface based on classes on a compound template. but I use hibernate to store my data, and I use annotations to map the data in the database. my problem is that I don’t know how to comment on my interface.

if any of you guys used a composite template storing data with hibernate

public interface Hierarchy(){
// a few abstract methods that will be implemented by the sub classes
 }


@Entity
@Table()
public class Folder implements Serializable, Hierarchy {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "folder_id", updatable = false, nullable = false)
private int id;
@OneToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
@JoinTable(name = "FOLDER_FILELOCATION", joinColumns = { 
        @JoinColumn(name = "folder_id") }, inverseJoinColumns = { 
        @JoinColumn(name = "file_information_id") })
private List<Hierarchy> children = new ArrayList<Hierarchy>() ;
@Column(name = "folder_name")
private String folderName;
@Column(name = "tree_item")
private TreeItem item;
@Column (name = "parent")
private Hierarchy parent;



@Entity
@Table(name = "FILE_INFORMATION_TABLE")
public class FileInformation implements Serializable, Hierarchy {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "file_information_id", updatable = false, nullable = false)
private int fiId;
@Column (name = "location")
private String location;
@Column(name = "tree_item")
private TreeItem item;
@Column (name = "parent")
    @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
    @JoinTable(name="FOLDER_FILELOCATION",
    joinColumns = @JoinColumn(name="filelocation_id"),
    inverseJoinColumns = @JoinColumn(name="folder_ID"))  
private Hierarchy parent;
+3
source share
3 answers

This Book . JPA. , . . , .

@Entity
@Table(name ="HIERARCHY")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(
    name = "HIERARCHY_TYPE", discriminatorType = DiscriminatorType.STRING)      
public abstract class  Hierarchy implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "hierarchy_id", updatable = false, nullable = false)
private int hId;



@Entity
@DiscriminatorValue("F")
public class Folder extends Hierarchy  {

@OneToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
@JoinTable(name = "FOLDER_JOIN_FILELOCATION", joinColumns = { 
        @JoinColumn(name = "folder_id") }, inverseJoinColumns = { 
        @JoinColumn(name = "file_information_id") })
private List<Hierarchy> children = new ArrayList<Hierarchy>() ;
@Column(name = "folder_name")
private String folderName;
//@Column(name = "tree_item")
//private TreeItem item;
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
   @JoinTable(name="FOLDER_JOIN_FOLDER",
        joinColumns = @JoinColumn(name="parent_folder_id"),
        inverseJoinColumns = @JoinColumn(name="folder_ID")
    ) 
private Hierarchy parent;




@Entity
@DiscriminatorValue("FI")
public class FileInformation extends Hierarchy  {


@Column (name = "location")
private String location;
//@Column(name = "tree_item")
//private TreeItem item;
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
   @JoinTable(name="FILEINFORMATION_JOIN_FOLDER",
        joinColumns = @JoinColumn(name="filelocation_id"),
        inverseJoinColumns = @JoinColumn(name="folder_ID")
    )  
private Hierarchy parent;
+1

Composite - .
. , FOLDER_FILELOCATION . , OneToMany, ManyToMany. OneToMany. ? , , . , , .

, , , , :

public interface Hierarchy(){
// a few abstract methods that will be implemented by the sub classes
}


@Entity
@Table(name = "FOLDER_TABLE")
public class Folder  implements Hierarchy, Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "folder_id", updatable = false, nullable = false)
    private int id;

    @OneToMany
    @JoinTable(
            name="FOLDER_FILELOCATION",
            joinColumns = @JoinColumn( name="folder_id"),
            inverseJoinColumns = @JoinColumn( name="filelocation_id")
    )   
    private List<Hierarchy> children = new ArrayList<Hierarchy>() ;

    @Column(name = "folder_name")
    private String folderName;

    @Column(name = "tree_item")
    private TreeItem item;

    @Column (name = "parent")
    private Hierarchy parent;
}

@Entity
@Table(name = "FILE_INFORMATION_TABLE")
public class FileInformation implements Hierarchy, Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "file_information_id", updatable = false, nullable = false)
    private int fiId;

    @Column (name = "location")
    private String location;
    @Column(name = "tree_item")
    private TreeItem item;

    @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
    @JoinTable(name="FOLDER_FILELOCATION",
        joinColumns = @JoinColumn(name="filelocation_id"),
        inverseJoinColumns = @JoinColumn(name="folder_ID")
    )   
    private Hierarchy parent;
}

, .

0

I am not 100% sure what you are trying to do (you are an extendinginterface, there is parentno annotation @ManyToOne), but as far as I know, the interface is not supported by annotations (they are not part of the JPA specification). See HHH-4413 as well as this discussion . For this, you may need XML mapping .

0
source

Source: https://habr.com/ru/post/1740392/


All Articles