8

I develop Spring Framework MVC application. Also I use hibernate. Now I make simple POJO for User entity.

@Entity
@Table(name="USERS")
public class User{
    @Column(name = "USERNAME", nullable = false, unique = true)
    private String username;
}
  • I configure org.springframework.orm.hibernate4.LocalSessionFactoryBean

My code is working, but IDEA show me a next warning.

Cannot resolve column 'USERNAME' less... (Ctrl+F1) This inspection controls whether the Persistence ORM annotations are checked against configured Datasources

What do I do wrong?

Everv0id
  • 1,862
  • 3
  • 25
  • 47
Daemon712
  • 83
  • 1
  • 4
  • i do not know IDEA enough... but i think you can configure datasources inside the IDEA so that the IDEA can better support you in development/jpa mapping... i think you could configure a datasource in IDEA. but this is only a speculation... but you could try it. – StefanHeimberg Sep 18 '15 at 21:07

3 Answers3

14

Press Alt+Enter when cursor is on USERNAME to view popup with available actions. You'll see an option "Configure data sources" or something like that, choose it, and you'll see a window. You should add new data source based on your database type (PostgreSQL, MySQL, etc) and configure it with your connection params.

Helpful link: Managing Data Sources

Roy
  • 656
  • 12
  • 28
Everv0id
  • 1,862
  • 3
  • 25
  • 47
6

1.Step 1

You must go to Project Structure under Project Settings select Modules

click on green plus icon then select Hibernate Then click Ok.

enter image description here

2.Step 2

Now you must assign data source to your Intellij, on the right side of Intellij window you can see this Database Icon, if doesn't exist you must mark View > Tool Buttons

enter image description here

click on green plus button and select Data Source and connect your database by this way.

3.Step 3

on the left side of Intellij you must see Presistence button like this below picture.

enter image description here

right click on getSessionFactory > Assing Data source .. then you must select your Data source to sessionFactory.

Note: if you update schema and update database you must update and sync database connected to you Intellij by click on refresh button in database window:

enter image description here

Note: this works for all of entity , the reason of you see red line of your property of some of entity class is your class name is more than one word and you must define table name in your @table like this:

@Entity
@Table(name = "user_info")
class UserInfo {
MostafaMashayekhi
  • 27,359
  • 3
  • 21
  • 39
2

You know, when Hibernate update to 4.3.x, it's going not to support @Table annotation. What changes is, when you need to define your table name in Model, you need to type like this: @Entity(name="tableName")

nthack
  • 444
  • 1
  • 3
  • 9