dimas wrote:
Very strange. I just checked similar code with my classes - everything work as expected.
Quote:
If I comment out the hole if-else part, then only the ProductOrder Constructor is called, noting else.
What happens if you replace if-else part with just
Code:
o.getText();
? Does Customer get initialized? If yes, could you please paste getText() here? I do not believe it is just plain getter :)
Just doing
Code:
o.getText();
leads to the unwanted behaviour that the Customer
object is created as well.
Here the complete ProductOrder code:
Code:
public class ProductOrder
{
private static final boolean DEBUG = true;
private static final boolean DEBUG2 = true;
private int clNo;
private int clProduct_Category;
private int clProduct_ID;
private Customer clCustomer; // instead of "customer_id"
private String clText;
private int clModified;
public ProductOrder(int no, int category, int product_id, String text)
{
clNo = no;
clProduct_Category = category;
clProduct_ID = product_id;
clCustomer = null;
clText = text;
clModified = 0;
if (DEBUG)
System.out.println("Constructor ProductOrder: " + clNo + ", " +
clProduct_Category + ", " + clProduct_Category + ", " +
clText + ", " + clModified);
}
public ProductOrder()
{
this(-1, -1, -1, null);
}
protected void finalize()
{
if (DEBUG)
System.out.println("Destructor ProductOrder: " + clNo + ", " + clProduct_Category +
", '" + clProduct_ID + "'");
}
public void setNo(int no)
{
clNo = no;
if (DEBUG2)
System.out.println("ProductOrder::setNo: " + clNo);
}
public int getNo()
{
if (DEBUG2)
System.out.println("ProductOrder::getNo: " + clNo);
return clNo;
}
public void setProductCategory(int category)
{
clProduct_Category = category;
if (DEBUG2)
System.out.println("ProductOrder::setCategory: " + clProduct_Category);
}
public int getProductCategory()
{
if (DEBUG2)
System.out.println("ProductOrder::getProductCategory: " + clProduct_Category);
return clProduct_Category;
}
public void setProductID(int id)
{
clProduct_ID = id;
if (DEBUG2)
System.out.println("ProductOrder::setID: " + clProduct_ID);
}
public int getProductID()
{
if (DEBUG2)
System.out.println("ProductOrder::getID: " + clProduct_ID);
return clProduct_ID;
}
public void setCustomer(Customer c)
{
clCustomer = c;
if (DEBUG2)
{
if (clCustomer == null)
System.out.println("ProductOrder::setCustomer: null");
else
System.out.println("ProductOrder::setCustomer: " + clCustomer.getName());
}
}
public Customer getCustomer()
{
if (DEBUG2)
{
if (clCustomer == null)
System.out.println("ProductOrder::getCustomer: null");
else
System.out.println("ProductOrder::getCustomer: " + clCustomer.getName());
}
return clCustomer;
}
public void setText(String text)
{
clText = text;
if (DEBUG2)
System.out.println("ProductOrder::setText: " + clText);
}
public String getText()
{
if (DEBUG2)
System.out.println("ProductOrder::getText: " + clText);
return clText;
}
public void setModified(int mod)
{
clModified = mod;
}
public int getModified()
{
return clModified;
}
}
I would guess that the reason for this behaviour is because of some missing/wrong
statements in one of my mapping files (see my first posting to this topic).