-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: hashcode and equals not used
PostPosted: Mon Feb 09, 2009 7:25 pm 
Newbie

Joined: Fri Jan 05, 2007 1:47 pm
Posts: 7
Hibernate version: 3.3

Mapping documents:
@Entity(name="T_APPLICATION")
public class Application {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="APPLICATION_ID")
private long id;

@Column(name="APPLICATION_NAME", nullable=false)
private String name;

@Column(name="APPLICATION_CODE", nullable=false, unique=true)
private String code;

@OneToMany(mappedBy="relatedApplication",
cascade=CascadeType.ALL)
private List<FileToParse> fileFormatsToMonitor;
...
}

@Entity(name="T_FILEFORMAT")
public class FileToParse {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="FILEFORMAT_ID")
private long id;

/**
* the path to the file, from the server
*/
@Column(name="FILEFORMAT_PATH")
private String path;

/**
* a regexp that will match the files we want to process
*/
@Column(name="FILEFORMAT_NAME")
private String filenameFormat;

@ManyToOne
@JoinColumn(name = "FILEFORMAT_RELATED_APPLICATION_ID")
@ForeignKey(name = "FK_FILE_APPLICATION")
private Application relatedApplication;

@OneToMany(mappedBy="relatedFile",
cascade=CascadeType.ALL,
fetch=FetchType.LAZY)
private List<IndicatorFromFile> indicatorsToGet=new ArrayList<IndicatorFromFile>();
...
}

@Entity(name="T_INDICATOR_FROM_FILE")
public class IndicatorFromFile {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="INDICATOR_FROM_FILE_ID")
private long id;

@ManyToOne
@JoinColumn(name = "INDICATOR_FROM_FILE_FILE_ID")
@ForeignKey(name = "FK_INDICATOR_FILE")
private FileToParse relatedFile;

@Column(name="INDICATOR_FROM_FILE_PATTERN")
private String pattern;
...
}





Code between sessionFactory.openSession() and session.close():
public List<FileToParse> getFileFormatForApplications(List<Application> applications){

if(applications==null){
return new ArrayList<FileToParse>();
}

Criteria criteria = hibernateTemplate.getSessionFactory().getCurrentSession().createCriteria(FileToParse.class);
criteria.add(Restrictions.in("relatedApplication", applications));
criteria.createAlias("indicatorsToGet", "indicators");
criteria.setFetchMode("indicators", FetchMode.JOIN);
return criteria.list();





Full stack trace of any exception that occurs:

Name and version of the database you are using:
mysql 5.1


The generated SQL (show_sql=true):
select
this_.fileformat_id as fileformat1_1_3_,
this_.fileformat_dateformat_filename as fileformat2_1_3_,
this_.fileformat_dateformat_timestamp as fileformat3_1_3_,
this_.fileformat_enable as fileformat4_1_3_,
this_.fileformat_name as fileformat5_1_3_,
this_.fileformat_findlogmsgregexp as fileformat6_1_3_,
this_.fileformat_findloglevelregexp as fileformat7_1_3_,
this_.fileformat_findtimestampregexp as fileformat8_1_3_,
this_.fileformat_last_analyzed as fileformat9_1_3_,
this_.fileformat_parser_classname as fileformat10_1_3_,
this_.fileformat_file_next_line as fileformat11_1_3_,
this_.fileformat_path as fileformat12_1_3_,
this_.fileformat_related_application_id as fileformat14_1_3_,
this_.fileformat_sorting as fileformat13_1_3_,
indicators1_.indicator_from_file_id as indicator1_6_0_,
indicators1_.indicator_from_file_attributetomap as indicator2_6_0_,
indicators1_.indicator_from_file_ismandatory as indicator3_6_0_,
indicators1_.indicator_from_file_iscreatepattern as indicator4_6_0_,
indicators1_.indicator_from_file_pattern as indicator5_6_0_,
indicators1_.indicator_from_file_pojoclassname as indicator6_6_0_,
indicators1_.indicator_from_file_file_id as indicator8_6_0_,
indicators1_.indicator_from_file_type as indicator7_6_0_,
filetopars4_.fileformat_id as fileformat1_1_1_,
filetopars4_.fileformat_dateformat_filename as fileformat2_1_1_,
filetopars4_.fileformat_dateformat_timestamp as fileformat3_1_1_,
filetopars4_.fileformat_enable as fileformat4_1_1_,
filetopars4_.fileformat_name as fileformat5_1_1_,
filetopars4_.fileformat_findlogmsgregexp as fileformat6_1_1_,
filetopars4_.fileformat_findloglevelregexp as fileformat7_1_1_,
filetopars4_.fileformat_findtimestampregexp as fileformat8_1_1_,
filetopars4_.fileformat_last_analyzed as fileformat9_1_1_,
filetopars4_.fileformat_parser_classname as fileformat10_1_1_,
filetopars4_.fileformat_file_next_line as fileformat11_1_1_,
filetopars4_.fileformat_path as fileformat12_1_1_,
filetopars4_.fileformat_related_application_id as fileformat14_1_1_,
filetopars4_.fileformat_sorting as fileformat13_1_1_,
applicatio5_.application_id as applicat1_2_2_,
applicatio5_.application_code as applicat2_2_2_,
applicatio5_.application_name as applicat3_2_2_
from t_fileformat this_
inner join t_indicator_from_file indicators1_ on this_.fileformat_id=indicators1_.indicator_from_file_file_id
left outer join t_fileformat filetopars4_ on indicators1_.indicator_from_file_file_id=filetopars4_.fileformat_id
left outer join t_application applicatio5_ on this_.fileformat_related_application_id=applicatio5_.application_id
where this_.fileformat_related_application_id in (1)



Hi,

Here's the deal: in my application, I managed one application, for which I have a List of FileToParse. In each FileToParse, I have several IndicatorFromFile.

I actually have 2 problems:
- When I try to load the FileToParse objects for a given Application, if I have only one FileToParse but 2 IndicatorFromFile linked to this FileToParse, it returns 2 FileToParse instead of one. I thought it was because I hadn't implemented hashCode and equals in FileToParse, so I implemented these methods, keeping only the relevant information, and removing from the comparison the indicatorsToGet attribute. It still doesn't work, but the weirdest thing is that it seems these methods are not used: I've set 2 breakpoints, one in each method, but when launched in debug, the debugger doesn't stop on them. It shoudl, shouldn't it ?
- Then, when trying to look into the indicatorsToGet attribute, I get a LazyInitializationException, even if I see from the SQL query that all the information regarding the IndicatorFromFile are retrieved. But I guess I need to fix the first problem first...

Thanks in advance

--
Vincent


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.