Forums Register Login

How to create relationship between parent and child tables

+Pie Number of slices to send: Send
Hi -

I am vary new to java. We are using java spring.

Here is what I have:

2 model class

1. parent
2 child

Parent model example:

{
private String pid;
private String []tableName;
private String rowNumber;
private String[] tableColumnName;
private String[] columnData;
private List<ChildTableInfo> ChildTableInfo;
public String getPid() {return pid;}
}

Child Model example:

{

private String parentName;
private String tableName;
private String rowNumber;
private String[] tableColumnName;
private String[] columnData;
}

Dummy_data class example:

public static List<TableInfo> getDummytableList = new ArrayList<TableInfo>();
static {



String[] colName = {"colName1","colName2","colName3","colName4"};
String[] colData = {"Data1","Data2","Data3","Data4"};

String[] childColData = {"ChildData1","ChildData2","ChildData3","ChildData4"};
String[] childColName = {"Child colName1","Child colName2","Child colName3","Child colName4"};
String[] tableName = {"A","B",C","D"};

List<ChildTableInfo>ChildTableInfo = new ArrayList<ChildTableInfo>();

ChildTableInfo childTableInfo1= new ChildTableInfo();

childTableInfo1.setTableName("F");
childTableInfo1.setColumnData(childColData);
childTableInfo1.setRowNumber("3");
childTableInfo1.setTableColumnName(childColName);
childTableInfo1.setParentName("D");
ChildTableInfo.add(childTableInfo1);

ChildTableInfo childTableInfo2= new ChildTableInfo();
childTableInfo2.setTableName("ET");
childTableInfo2.setColumnData(childColData);
childTableInfo2.setRowNumber("2");
childTableInfo2.setTableColumnName(childColName);
childTableInfo2.setParentName("D");
ChildTableInfo.add(childTableInfo2);




List<TableInfo> pidAtableList = new ArrayList<TableInfo>();

TableInfo pida1 = new TableInfo();
pida1.setPid("84");

pida1.setRowNumber("1");
pida1.setTableColumnName(colName);
pida1.setColumnData(colData);
pida1.setTableName(tableName);
pidAtableList.add(pida1);

ParticipantTableInfo pida2 = new ParticipantTableInfo();
pida2.setPid("84");

pida2.setRowNumber("23");
pida2.setColumnData(colData);
pida2.setTableColumnName(colName);
pidAtableList.add(pida2);

TableInfo pida3 = new TableInfo();
pida3.setPid("84");

pida3.setRowNumber("1");
pida3.setColumnData(colData);
pida3.setTableColumnName(colName);
pidAtableList.add(pida3);

TableInfo pida4= new TableInfo();
pida4.setPid("84");

pida4.setRowNumber("1");
pida4.setColumnData(colData);
pida4.setTableColumnName(colName);
pida4.setChildTableInfo(ChildTableInfo);
pidAtableList.add(pida4);

getDummytableList.addAll(pidAtableList);


List<TableInfo> pidBtableList = new ArrayList<TableInfo>();
TableInfo pidb1 = new TableInfo();
pidb1.setPid("35239523");

pidb1.setRowNumber("1");
pidb1.setTableColumnName(colName);
pidb1.setColumnData(colData);
pidBtableList.add(pidb1);

TableInfo pidb2 = new TableInfo();
pidb2.setPid("35239523");

pidb2.setRowNumber("5");
pidb2.setColumnData(colData);
pidb2.setTableColumnName(colName);
pidBtableList.add(pidb2);

TableInfo pidb3 = new TableInfo();
pidb3.setPid("35239523");

pidb3.setRowNumber("0");
pidb3.setColumnData(colData);
pidb3.setTableColumnName(colName);
pidBtableList.add(pidb3);

TableInfo pidb4= new TableInfo();
pidb4.setPid("35239523");

pidb4.setRowNumber("2");
pidb4.setColumnData(colData);
pidb4.setTableColumnName(colName);
pidb4.setChildTableInfo(tChildTableInfo);
pidBtableList.add(pidb4);

getDummytableList.addAll(pidBtableList);

}


I need to show the above information in hierarchical form.

Thanks.
+Pie Number of slices to send: Send
First of all put your code inside code tags and with proper indentation, so that it's easier to read. Now coming to your question,

1. We don't see any setter and getter methods in the model classes.

2. If that Child model class is a child of the Parent model class, then why are you repeating attributes in the child class?
+Pie Number of slices to send: Send
 

Rachna Chawla wrote:I am vary new to java. We are using java spring.


Well that sounds like a mistake right there. Spring is a framework that adds a lot of additional stuff you need to know about to standard Java, which might lead to overload if you're also trying to learn plain old Java at the same time.

On top of that, you also appear to be dealing with database tables, which is yet another thing you need to understand. And parent→child relationships for tables are set up by following rules dictated by SQL or the database you're using; not Java.
[Edit:] Unless Spring itself contains classes for constructing this sort of stuff; but if so, I don't see any evidence that you're using them.

My advice: Back up and explain what you're trying to do, not how you intend to do it. A good start might be to give us the description of your problem as it was given to you, because honestly, I'm having a hard time trying to work out what it is you want.

Winston
Let's get him boys! We'll make him read this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 457 times.
Similar Threads
Need an idea regarding my billing application.
Invalid column type
Constructors Problem
Form a tree parent -childs from String
JTable problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 20:02:08.