-->
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.  [ 6 posts ] 
Author Message
 Post subject: How can I avoid adding "id" to my interface?
PostPosted: Fri Jun 02, 2006 1:04 pm 
Beginner
Beginner

Joined: Mon Aug 15, 2005 10:20 am
Posts: 32
Location: Brazil
Is there some way to avoid adding an "id" to interfaces?

eg.:
Code:
public interface Employee
{
    public double getSalary();
}

public class SalariedEmployee implements Employee
{
    private Long id;
    private double salary;

    public Long getId() { return id; }
    public void setid(Long id) { this.id = id; }

    public double getSalary { return salary; }
    public void setSalary(double salary) { this.salary = salary; }
}

How can I associate with Employee, without polluting it with "getId()"?

Thanks in advance,
Daniel Serodio


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 02, 2006 1:55 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
abstract class?

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 02, 2006 2:48 pm 
Newbie

Joined: Wed Feb 08, 2006 3:57 pm
Posts: 16
1. What do you want associate with Employee?
2. How would you like to identify the Employee?


Top
 Profile  
 
 Post subject: Re: How can I avoid adding "id" to my interface?
PostPosted: Fri Jun 02, 2006 4:15 pm 
Beginner
Beginner

Joined: Tue Oct 18, 2005 3:57 pm
Posts: 48
Location: Los Angeles, CA
DanielSerodio wrote:
Is there some way to avoid adding an "id" to interfaces?

You can skip the "name" attribute in the mapping and let Hibernate handle the identifier for you:

Code:
<id column="EMP_ID">....</id>

Then your class will look like:

Code:
public class SalariedEmployee implements Employee
{
    private double salary;

    public double getSalary { return salary; }
    public void setSalary(double salary) { this.salary = salary; }
}


Top
 Profile  
 
 Post subject: Re: How can I avoid adding "id" to my interface?
PostPosted: Mon Jun 05, 2006 9:58 am 
Beginner
Beginner

Joined: Mon Aug 15, 2005 10:20 am
Posts: 32
Location: Brazil
jd001982 wrote:
DanielSerodio wrote:
Is there some way to avoid adding an "id" to interfaces?

You can skip the "name" attribute in the mapping and let Hibernate handle the identifier for you:

Code:
<id column="EMP_ID">....</id>

Should I skip the "name" attribute for the class element, or the id element?


Top
 Profile  
 
 Post subject: Re: How can I avoid adding "id" to my interface?
PostPosted: Tue Jun 06, 2006 3:08 pm 
Beginner
Beginner

Joined: Tue Oct 18, 2005 3:57 pm
Posts: 48
Location: Los Angeles, CA
Quote:
Should I skip the "name" attribute for the class element, or the id element?

<id> element. Normally you'd have an id property for a class:
Code:
public class Foo {
    private long id;
}

with a mapping looking like this:
Code:
<class ....>
    <id name="id" column="FOO_ID">...</id>

But if you don't want the hassle of keeping an id property, then you do what I'd mentioned before, i.e. skip the name attribute in your mapping:
Code:
<class ....>
    <id column="FOO_ID">...</id>


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

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.