public void protectObjectInternalConditional(Integer ownerTableId, Long ownerId, String relationName,
			Integer propertyTableId, Long propertyId, Integer classNameId, ConnectionWrapper cw) throws SQLException
	{
		StringBuilder statement = new StringBuilder(150);
		statement.append("SELECT COUNT(*) FROM ");
		statement.append(Defaults.HAS_A_TABLENAME);
		statement.append(" WHERE PROPERTY_TABLE = ? AND PROPERTY_ID = ? AND OWNER_TABLE=? AND OWNER_ID=?");
		PreparedStatement ps = cw.prepareStatement(statement.toString());
		try
		{
			ps.setInt(1, propertyTableId);
			ps.setLong(2, propertyId);
			ps.setInt(3, ownerTableId);
			ps.setLong(4, ownerId);
			Tools.logFine(ps);
			ResultSet rs = ps.executeQuery();
			// check if the query returns no results
			if (!rs.next() || rs.getLong(1)<=0)
			{
				protectObjectInternal(ownerTableId, ownerId, relationName, propertyTableId, propertyId, classNameId, cw);
			}
		}
		finally
		{
			ps.close();
		}
	}