• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to create relationship between parent and child tables

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic