Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
/HibernateHelloWorld/target/
/CompositeExercise/target/
HibernateHelloWorld/target/
CompositeExercise/target/
DemoOneToOne/target/
DemoOneToMany/target/
JPAExercise/target/
HibernateAuctions/target/
33 changes: 33 additions & 0 deletions DemoOneToMany/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>DemoOneToMany</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.2.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5</version>
</dependency>
<!-- https://search.maven.org/remotecontent?filepath=org/apache/commons/commons-lang3/3.9/commons-lang3-3.9.jar -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@

package com.mycompany.demoonetomany.Entity;

import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

/**
*
* @author naagarjunaa
*/
@Entity
public class Attachment {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(updatable = false, nullable = false)
private int a_id;
private String fileName;
private String fileSize;
private Timestamp Created;
private byte AttachmentBytes;
@ManyToOne()
@JoinColumn(name = "proposal_docid")
private Proposal proposal;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "pesonnel_p_id")
private Personnel personnel;

public Attachment() {
}

public Attachment(String fileName, String fileSize, Timestamp Created, byte AttachmentBytes) {
this.fileName = fileName;
this.fileSize = fileSize;
this.Created = Created;
this.AttachmentBytes = AttachmentBytes;
}

public Attachment(int a_id, String fileName, String fileSize, Timestamp Created, byte AttachmentBytes) {
this.a_id = a_id;
this.fileName = fileName;
this.fileSize = fileSize;
this.Created = Created;
this.AttachmentBytes = AttachmentBytes;
}

public Proposal getProposal() {
return proposal;
}

public void setProposal(Proposal proposal) {
this.proposal = proposal;
}

public Personnel getPersonnel() {
return personnel;
}

public void setPersonnel(Personnel personnel) {
this.personnel = personnel;
}

public int getA_id() {
return a_id;
}

public void setA_id(int a_id) {
this.a_id = a_id;
}

public String getFileName() {
return fileName;
}

public void setFileName(String fileName) {
this.fileName = fileName;
}

public String getFileSize() {
return fileSize;
}

public void setFileSize(String fileSize) {
this.fileSize = fileSize;
}

public Timestamp getCreated() {
return Created;
}

public void setCreated(Timestamp Created) {
this.Created = Created;
}

public byte getAttachmentBytes() {
return AttachmentBytes;
}

public void setAttachmentBytes(byte AttachmentBytes) {
this.AttachmentBytes = AttachmentBytes;
}
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

package com.mycompany.demoonetomany.Entity;

import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

/**
*
* @author naagarjunaa
*/
@Entity
public class Personnel {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(updatable = false, nullable = false)
private int p_id;
@Column(length = 60)
private String name;
private String QualificationLevel;
private String phone;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "proposal_docid")
private Proposal proposal;
@OneToMany(mappedBy = "personnel",orphanRemoval = true,cascade = CascadeType.ALL)
private List<Attachment> attachment;

public Personnel() {
}

public Personnel(String name, String QualificationLevel, String phone) {
this.name = name;
this.QualificationLevel = QualificationLevel;
this.phone = phone;
}

public Personnel(int p_id, String name, String QualificationLevel, String phone) {
this.p_id = p_id;
this.name = name;
this.QualificationLevel = QualificationLevel;
this.phone = phone;
}

public Proposal getProposal() {
return proposal;
}

public void setProposal(Proposal proposal) {
this.proposal = proposal;
}

public List<Attachment> getAttachment() {
return attachment;
}

public void setAttachment(List<Attachment> attachment) {
this.attachment = attachment;
}

public int getP_id() {
return p_id;
}

public void setP_id(int p_id) {
this.p_id = p_id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getQualificationLevel() {
return QualificationLevel;
}

public void setQualificationLevel(String QualificationLevel) {
this.QualificationLevel = QualificationLevel;
}

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

// public void add(Proposal propl){
// if (proposal == null){
// proposal = new ArrayList<>();
// }
//}
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@

package com.mycompany.demoonetomany.Entity;

import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

/**
*
* @author naagarjunaa
*/
@Entity
public class Proposal {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(updatable = false, nullable = false)
private long DocID;
@Column(length = 100)
private String Title;
@Column(length = 1000)
private String Comment;

@OneToMany(mappedBy = "proposal",orphanRemoval = true, cascade = CascadeType.ALL)//,cascade = CascadeType.ALL
private List<Personnel> personnel;

@OneToMany(mappedBy = "proposal",orphanRemoval = true, cascade = CascadeType.ALL)
private List<Attachment> attachments;

public Proposal() {
}

public Proposal(String Title, String Comment) {
this.Title = Title;
this.Comment = Comment;
}

public Proposal(long DocID, String Title, String Comment) {
this.DocID = DocID;
this.Title = Title;
this.Comment = Comment;
}

public long getDocID() {
return DocID;
}

public void setDocID(long DocID) {
this.DocID = DocID;
}

public String getTitle() {
return Title;
}

public void setTitle(String Title) {
this.Title = Title;
}

public String getComment() {
return Comment;
}

public void setComment(String Comment) {
this.Comment = Comment;
}

public List<Personnel> getPersonnel() {
return personnel;
}

public void setPersonnel(List<Personnel> personnel) {
this.personnel = personnel;
}

public List<Attachment> getAttachments() {
return attachments;
}

public void setAttachments(List<Attachment> attachments) {
this.attachments = attachments;
}

@Override
public String toString() {
return ReflectionToStringBuilder.toString(this);
}

}
Loading