2

I have MySQL database with some tables there, and in my Workbench everything is fine, but when I make connection in eclipse, with that database, and open inspector in eclipse, to see tables, there is a problem that in table 'uloga' there are some columns that shouldn't be there. That is of course a problem, when I try to generate models using Hibernate I have in class Uloga fields that shouldn't be there, because Hibernate generates model classes from connection. This is model of my database: This is model of my database

This is how does it look in my workbench: This is how does it look in my workbench

And this is how does it look in eclipse, when I make connection to db: And this is how does it look in eclipse, when I make connection to db

Is there any solution for this issue ?

1
  • 1
    Do you have additional fields in your Uloga class in code, that are not present in the database? Commented Jan 21, 2020 at 10:46

4 Answers 4

1

All of fields you don't want to be mapped to your database need to be annotated with @Transient. This annotation will 'tell' hibernate to ignore fields annotated with it.

This annotation is in javax.persistence package.

https://docs.oracle.com/javaee/7/api/javax/persistence/Transient.html

@Edit: You really don't need to define tables in your database while working with hibernate. It will define them automatically. I would try to drop table uloga, or at least redefine it, and then run the program.

Sign up to request clarification or add additional context in comments.

Comments

0

Yes I have. This is how does my class Uloga looks like There are four fields, that they are not in database. Fields like idGlumac, idPredstava and etc shouldn't be in this class.

Comments

0

Yes i know that, but there is another problem. I make classes from database, and when I make connection it makes me table Uloga with more columns then I have it in database. After that everything is a problem, making classes makes me errors and etc. Did I explain problem very well ?

Comments

0

I found what problem was. I had in my database one more database, that have table with same name, and in mapping in eclipse when I make connection, connection had joining these two tables in one. Very stupid issue that I spent my last day on it. If you don't know how to spent your time in stupid way, please call me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.