title: Hibernate Could not determine type for column
body: <p>I had problem with simple One to One mapping in hibernate.
  I had Two simple classes:</p>
  
  <p>First Entity:</p>
  
  <pre><code>@Entity
  public class GrantingOfLoanData {
  
      @Id
      @GeneratedValue
      private Long id;
  
      @OneToOne(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
      @JoinColumn(name="loan", referencedColumnName="loan_id")
      public Loan getLoan() {
          return loan;
      }
      private Loan loan;
  }
  </code></pre>
  
  <p>Second Entity:</p>
  
  <pre><code>@Entity
  public class Loan {
  
      @Id
      @GeneratedValue
      @Column(name="loan_id")
      private Long loan_id;
  
      public Long getLoan_id() {
          return loan_id;
      }
  }
  </code></pre>
  
  <p>When I trying to run this code with hibernate I got followed exception:</p>
  
  <pre><code>Caused by: org.hibernate.MappingException: Could not determine type for: org.finance.app.core.domain.common.loan.Loan, at table: GrantingOfLoanData, for columns:     [org.hibernate.mapping.Column(loan)]
  at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:336) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
  at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:310) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
  at org.hibernate.mapping.Property.isValid(Property.java:241) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
  at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:496) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
  at org.hibernate.mapping.RootClass.validate(RootClass.java:270) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
  at org.hibernate.cfg.Configuration.validate(Configuration.java:1358) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1849) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
  at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) ~[hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
  </code></pre>
  
  <p>I am using Spring version 4.0.5 and trying to be xml-less so as I understood the LocalContainerEntityManagerFactoryBean now supports a ‘packagesToScan’ property where the packages to scan for @Entity classes can be specified.</p>
  
  <p>my @Configuration JPA class looks as follow:</p>
  
  <pre><code>@Configuration
  @EnableTransactionManagement
  @PropertySource({ "classpath:persistence-pgsql.properties" })
  @ComponentScan({ "org.finance.app" })
  public class PersistenceJPAConfig {
  
  @Autowired
  private Environment env;
  
  public PersistenceJPAConfig() {
      super();
  }
  
  // beans
  
  @Bean
  public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
      final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
      em.setDataSource(dataSource());
      em.setPackagesToScan(new String[] { "org.finance.app" });
  
      final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
      em.setJpaVendorAdapter(vendorAdapter);
      em.setJpaProperties(additionalProperties());
  
      return em;
  }
  
  @Bean
  public DataSource dataSource() {
      final DriverManagerDataSource dataSource = new DriverManagerDataSource();
      dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName")));
      dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url")));
      dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user")));
      dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass")));
  
      return dataSource;
  }
  
  @Bean
  public PlatformTransactionManager transactionManager(final EntityManagerFactory emf) {
      final JpaTransactionManager transactionManager = new JpaTransactionManager();
      transactionManager.setEntityManagerFactory(emf);
      return transactionManager;
  }
  
  @Bean
  public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
      return new PersistenceExceptionTranslationPostProcessor();
  }
  
  final Properties additionalProperties() {
      final Properties hibernateProperties = new Properties();
      hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
      hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
      return hibernateProperties;
     }
  }
  </code></pre>