Witajcie uczę się Hibernate z kursu: http://summerofnhibernate.com/
Krok po kroczku robiłem tak, jak jest to w nim napisane (tylko solucję sobie nazwałem inaczej ale to nie ma znaczenia).
Próbuję skompilować projekt i pobrać sobie w konsolce dane użytkownika.
Lecz w chwili gdy wywołuję procedurę:
public DataTransfer.Customer GetCustomerById(int id)
{
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
config.Configure();
NHibernate.ISessionFactory sessionFactory = config.BuildSessionFactory();
NHibernate.ISession session = sessionFactory.OpenSession();
// return (DataTransfer.Customer)session.Get(typeof(DataTransfer.Customer), id);
return session.Get<DataTransfer.Customer>(id);
metoda:
public DataTransfer.Customer GetCustomerById(int id)
{
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
config.Configure();
NHibernate.ISessionFactory sessionFactory = config.BuildSessionFactory();
NHibernate.ISession session = sessionFactory.OpenSession();
// return (DataTransfer.Customer)session.Get(typeof(DataTransfer.Customer), id);
return session.Get<DataTransfer.Customer>(id);
}
Dostaję błąd:
**Unable to locate persister for the entity named 'DataTransfer.Customer'.
The persister define the persistence strategy for an entity.
Possible causes:
The mapping for 'DataTransfer.Customer' was not added to the NHibernate configuration.**</li>
</ul>
Czytałem o tym i polecają aby zrobić embeded resource z pliczku Customer.hbm.xml,
tak zrobiłem (dodałem go jako Embeded) a mimo to problem nadal występuje.
Pliczek Customer.hbm.xml":
```xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DataTransfer" namespace="DataTransfer" >
<class name="DataTransfer.Customer,DataTransfer" table="Customer">
<id name="CustomerId" column="CustomerId" type="Int32" unsaved-value="0">
<generator class="native"></generator>
</id>
<property name="Firstname" column="Firstname" type="string" length="50" not-null="false"/>
<property name="Lastname" column="Lastname" type="string" length="50" not-null="false"/>
</class>
</hibernate-mapping>
Co może być tego przyczyną?
Pełne źródła solucji: http://wyslijto.pl/plik/0hny93qn8f
usunięcie pustych linii z bloku kodu + zamiana znacznika <code class="csharp"> na <code class="xml"> dla zawartości pliku "Customer.hbm.xml" - fp