herencia mysql con tablas

I am programming in Java and I have a three classes.

Uno de ellos es User. The other classes are UserTeacher y UserStudent. Ambos heredan de User.

I have to implement tables in a mysql database to store the values. What would you do? User tiene los atributos username, pw, firstname y lastname.

preguntado el 12 de junio de 12 a las 18:06

Depending on how much effort you want to put into this, and how extensible it needs to be, you might look at a ORM like Hibernate. -

1 Respuestas

Make one table with an extra attribute, besides username, pw, firstname, called userType. Was there something else you meant to ask?

Edit. You could also split up the tables into something like:

UserTeacher: firstname, passwd, username
UserStudent: firstname, passwd, username
User: firstname, username

But I still think the first way is better considering that the teacher and student classes only differ in terms of who they are but not their attributes (well at least not mentioned ones). If you do have a lot of other attributes I'd recomend somethign as follows:

UserTeacher: firstname, username, attr1, attr2, attrN
UserStudent: firstname, username, attr1, attr2, attrN
User: firstname, username, passwd 

Respondido el 12 de junio de 12 a las 18:06

is there really no better way? if you can see i have something like of course table student and teacher will get a lot of attributes later - Florian

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.